#include
#include
main()
{
 int i,j,n,counter=0;
 char file[50],str[20],buf[20];
 FILE *fp;
 printf("\nEnter file name with path and string :");
 gets(file);
 gets(str);
        puts(file);
 puts(str);
  fp=fopen(file,"r");
 while(fgets(buf,sizeof(buf),fp)!='\0')
 {      
  if(strstr(buf,str))
  { 
   printf("\n");
    puts(buf); 
    counter++;
  }
 }
        printf("\nThe number of time string find is :%d\n",counter);
 fclose(fp);
}
 
May be it's time you start using subroutines
ReplyDelete