-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.c
70 lines (62 loc) · 1.04 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void s_skip_line(FILE *fp)
{ int ch;
do
{ ch=getc(fp);
} while (ch!=EOF && ch!='\n');
ungetc(ch,fp);
}
int s_skipblanks(FILE *fp)
{ int i=0, ch;
do
{ ch=getc(fp);
i++;
} while (isspace(ch));
ungetc(ch,fp);
return ch;
}
int s_search_in_file_ncs(FILE *f, char *s)
/* Not case sensitive */
{ int l=0, ch;
int is, ilen, found=0;
ilen=strlen(s);
do
{ ch=getc(f);
is=0;
while (tolower(ch)==tolower(s[is]))
{ ch=getc(f);
if (ch==EOF) break;
is++;
if (is==ilen)
{ found=1;
break;
}
}
} while (!found && ch!=EOF);
ungetc(ch,f);
return found;
}
int s_search_in_file(FILE *f, char *s)
{ int l=0, ch;
int is, ilen, found=0;
ilen=strlen(s);
do
{ ch=getc(f);
is=0;
while (ch==s[is])
{ ch=getc(f);
if (ch==EOF) break;
is++;
if (is==ilen)
{ found=1;
break;
}
}
} while (!found && ch!=EOF);
ungetc(ch,f);
return found;
}