home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / Replacements / MatchV2_0.lha / MatchV2.0.c < prev   
Encoding:
C/C++ Source or Header  |  1996-03-12  |  1.1 KB  |  62 lines

  1. #include <stdio.h>
  2. main(argc,argv)
  3. int argc;
  4. char **argv;
  5.    {
  6.    int x,z,s,n=0,tot=0;
  7.    char key[255],data[255],a[255],b[255];
  8.    FILE *stream;
  9.  
  10.    printf("Match V2.0 Ioannis Nobelis 1996\n");
  11.    if (argc <= 2)
  12.       {
  13.       puts("Required argument missing");
  14.       exit(20);
  15.       }
  16.    if (strlen(argv[2]) < 3)
  17.       {
  18.       puts("Supply at least 3 characters for search");
  19.       exit(20);
  20.       }
  21.    strcpy(a,argv[2]);
  22.    strlwr(a);
  23.  
  24.    stream = fopen(argv[1],"r");
  25.    if (stream == NULL)
  26.       {
  27.       printf("File not found.\n");
  28.       exit(20);
  29.       }
  30.    while (!feof(stream))
  31.       {
  32.       ++n;
  33.       fgets(data,255,stream);
  34.       s=0;
  35.       while (data[s] != '\n')
  36.          {
  37.          ++s;
  38.          }
  39.       strcpy(b,data);
  40.       strlwr(b);
  41.       z=0;
  42.       while (z<s)
  43.          {
  44.          x=0;
  45.          while (a[x] == b[z+x])
  46.             {
  47.             ++x;
  48.             if (a[x] == '\0')
  49.                {
  50.                ++tot;
  51.                printf("%5d> %s",n,data);
  52.                goto keep;
  53.                }
  54.             }
  55.          ++z;
  56.          }
  57.       keep:
  58.       }
  59.    fclose(stream);
  60.    printf("\nString matched in %d lines.\n",tot);
  61.    }
  62.