I am reading words from file & need to search some specific words, below is my code
string read = malloc(50 * sizeof(char));
FILE* p = fopen("word","r");
while(fgets(read,50,p))
{
printf("%s\n",read);
if(strcmp(read,"apple") == 0)
{
printf("apple found\n");
break;
}
}
And sample file 'word' is as below,
$: more word
liol
apple
scizzors
big
bang
mentalist
scapegrace
goat
goti
Why is strcmp not working in this case, printf can print string read, so char pointer is working fine.