searching a string in file -c program
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char yourtext[20]="europe";
char file[20]="filename";
char buf[100];
FILE *fp=fopen("file.txt","a+");
char *p;
//fgets is a function which takes a //line input from a file till a new line //character fgets(char[ ],int,FILE *)
while(fgets(buf,100,fp))
{
p=strstr( buf , yourtext);
if(p!=NULL)
{
printf("%s",p);
exit(0);
}
}
printf("Not found\n ");
return 0;
}
0 comments:
Post a Comment