comparing a string from a file

guys could anyone help me how to compare a strinf from a file.
example i entered the word "plus" then the program should search
it from a file then print if it is true or not.. please help me :D

this is my code:

wlist.txt contains words to be compared by get

#include<stdio.h>
main()
{
FILE *fp;
char get,store;
fp=fopen("i:\\wlist.txt","r");
printf("Enter word to find: ");
scanf("%s",&get);
strcpy(&get);
while(fp!=EOF){
fscanf(fp,"%s\n",store);}
if(strcmp(store,get)==1)
{
printf("Found! %s",store);
getch();
}
else
printf("Not Found!");
getch();
}


please help me to correct this error..
Last edited on
Hi,

First of all, have a look at your while loop. It only contains the fscanf(fp,"%s\n",store); statement. You need to include the if-else statement in with the while loop.

Also, you need to declare get and store as pointers to char (char *) or as a char array (e.g. char foo_str[50]), not just char. Have a look at this tutorial (random one from Google) http://www.cprogramming.com/tutorial/lesson9.html

Tom.
Last edited on
Topic archived. No new replies allowed.