Implementation of GREP -N command in C

#include<stdio.h>
#include<string.h>

void main()
{
                    FILE *fp;
                   char line[100],lineu[100];
                   int count=0;

                    fp = fopen(argv[3],"r");
 
                    strupr(argv[2]);

                while(fscanf(fp , "%[^\n]\n" , line)!=EOF)
               {
                         count++;
                         strcpy(lineu,line);
                         strupr(lineu);
                         if(strstr(lineu , argv[2]) !=NULL)
                         {
                               printf("%d .%s\n" ,count, line);
                          }
                          else
                         {
                               continue;
                          }
                       
                 }
                 fclose(fp);
}


OUTPUT:

cc grep.c
./a.out  -n "word"   filename

Comments