home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
waffle
/
aser28.zip
/
MATCHSTR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-02
|
843b
|
40 lines
/*
Check Whether a given string matches with substings in a file
return: 0 if no match
-1 error
x match at line x
1991, Budi Rahardjo <budi@bison.mb.ca>
*/
#include <stdio.h>
#include <string.h>
#define MS_MAXCHAR 80
matchstring(string,filename)
char *string, *filename;
{
FILE *FN;
char *longstr;
char substr[MS_MAXCHAR+1];
int entry=1;
FN = fopen(filename,"r");
if (FN==NULL) {
printf("Can not open %s\n", filename);
return(-1); }
longstr = strlwr(strdup(string));
while (fgets(substr,MS_MAXCHAR,FN)) {
substr[strlen(substr)-1]='\0';
#ifdef DEBUG
printf("%s\n",substr);
#endif
if (strstr(longstr,substr)!=NULL) { /* FOUND */
fclose(FN);
return(entry);
}
entry++;
}
fclose(FN);
return(0);
}