Tuesday, May 12, 2020

C prog on isgrep

C Program to Simulate grep Command in Linux


#include<stdio.h>
#include<string.h>
void main()
{
char f1[10],ptrn[10],t[200];
FILE *fp;
printf("Enter file name\n");
scanf("%s",f1);
printf("Enter pattern \n");
scanf("%s",ptrn);
fp=fopen(f1,"r");
while(!feof(fp))
{
fgets(t,1000,fp);
if(strstr(t,ptrn))
  printf("%s",t);
}
fclose(fp);
}

No comments:

Post a Comment