#include<stdio.h>
#include<string.h>
void main(int argc , char *argv[])
{
FILE *fp;
char line[100],lineu[100];
// initialise the file pointer
fp = fopen(argv[3],"r");
convert to upper case
strupr(argv[2]);
while(fscanf(fp , "%[^\n]\n" , line)!=EOF)
{
strcpy(lineu,line);
strupr(lineu);
if(strstr(lineu , argv[2]) !=NULL)
{
printf("%s\n" , line);
}
else
{
continue;
}
}
fclose(fp);
}
output:
cc grep.c
./a.out -i "word" filename
#include<string.h>
void main(int argc , char *argv[])
{
FILE *fp;
char line[100],lineu[100];
// initialise the file pointer
fp = fopen(argv[3],"r");
convert to upper case
strupr(argv[2]);
while(fscanf(fp , "%[^\n]\n" , line)!=EOF)
{
strcpy(lineu,line);
strupr(lineu);
if(strstr(lineu , argv[2]) !=NULL)
{
printf("%s\n" , line);
}
else
{
continue;
}
}
fclose(fp);
}
output:
cc grep.c
./a.out -i "word" filename
Comments
Post a Comment