comparing a string from a file in C
Dec 21, 2010 at 3:46pm UTC
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#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 any mistakes in this code.. i don't know why it doesn't work.. i hope anyone could help me..
please help me to correct this error..
Last edited on Dec 22, 2010 at 7:35am UTC
Dec 21, 2010 at 4:06pm UTC
strcmp returns 0 when strings are equal.
if (strcmp(store,get)==0) // should work fine now
And when posting code, please use [co de][/co de] tags to make code more readable
Topic archived. No new replies allowed.