hi all, i have a code which searches for a string in a file, the searching works well except that it will only return that the string is found if it is the first word in the file, otherwise it will return not found. help me please
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fp,*fout;
int i=0,len_string;
char SearchText[30];
char temp[30];
printf("Enter the string: ");
scanf("%s", &SearchText);
fp=fopen("log.txt","a+");
rewind(fp); /* for going to start of file. */
if(fp==NULL )
{
printf("File couldn't be opened ");
exit(0);
}
len_string=strlen(SearchText);
while(!feof(fp))
{
for(i=0;i<len_string;i++) temp[i]=fgetc(fp);
temp[i]='\0';
if(stricmp(SearchText,temp)==0) /* the stricmp() is used for comparing both string. */
{
printf("The string is found!");
fflush(fp);
fclose(fp);
getch();
exit(1);
}
else
{
printf("NOT FOUND");
getch();
exit(1);
}
fseek(fp,-(len_string-1),1);
}
fclose(fp);
}