#include <stdio.h>
main(argc,argv)
int argc;
char **argv;
   {
   int x,z,s,n=0,tot=0;
   char key[255],data[255],a[255],b[255];
   FILE *stream;

   printf("Match V2.0 Ioannis Nobelis 1996\n");
   if (argc <= 2)
      {
      puts("Required argument missing");
      exit(20);
      }
   if (strlen(argv[2]) < 3)
      {
      puts("Supply at least 3 characters for search");
      exit(20);
      }
   strcpy(a,argv[2]);
   strlwr(a);

   stream = fopen(argv[1],"r");
   if (stream == NULL)
      {
      printf("File not found.\n");
      exit(20);
      }
   while (!feof(stream))
      {
      ++n;
      fgets(data,255,stream);
      s=0;
      while (data[s] != '\n')
         {
         ++s;
         }
      strcpy(b,data);
      strlwr(b);
      z=0;
      while (z<s)
         {
         x=0;
         while (a[x] == b[z+x])
            {
            ++x;
            if (a[x] == '\0')
               {
               ++tot;
               printf("%5d> %s",n,data);
               goto keep;
               }
            }
         ++z;
         }
      keep:
      }
   fclose(stream);
   printf("\nString matched in %d lines.\n",tot);
   }
