home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / waffle / aser28.zip / MATCHSTR.C < prev    next >
C/C++ Source or Header  |  1991-12-02  |  843b  |  40 lines

  1. /*
  2. Check Whether a given string matches with substings in a file
  3. return: 0    if no match
  4.        -1    error
  5.         x    match at line x
  6.  
  7. 1991, Budi Rahardjo <budi@bison.mb.ca>
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #define MS_MAXCHAR 80
  12.  
  13. matchstring(string,filename)
  14. char *string, *filename;
  15.    {
  16.    FILE *FN;
  17.    char *longstr;
  18.    char substr[MS_MAXCHAR+1];
  19.    int entry=1;
  20.    FN = fopen(filename,"r");
  21.    if (FN==NULL) { 
  22.       printf("Can not open %s\n", filename);
  23.       return(-1); }
  24.    longstr = strlwr(strdup(string));
  25.    while (fgets(substr,MS_MAXCHAR,FN)) {
  26.       substr[strlen(substr)-1]='\0';
  27. #ifdef DEBUG
  28.       printf("%s\n",substr);
  29. #endif
  30.       if (strstr(longstr,substr)!=NULL) { /* FOUND */
  31.      fclose(FN);
  32.      return(entry);
  33.      }
  34.       entry++;
  35.       }
  36.    fclose(FN);
  37.    return(0);
  38.    }
  39.  
  40.