0

Could you tell me what is wrong here?

I am working on simple program in c that can be used for searching words in text file. I know how to do that however during writting a code I was trying to make it as short as I can and accidentally make something similar to this. I realised that actually I am not sure why this version doesn't work properly. Any suggestions? #include <stdio.h> #include <string.h> int main() {     FILE *ptr;     char taken[6000];     char searched[20];     int appearances;     ptr=fopen("C:\\Users\\euro\\Desktop\\docwysz.txt","r");     if(ptr==NULL)     {         perror("Error opening file");         return(-1);     }     else         {         fgets(searched,20,stdin);         fgets(taken,20,ptr);        if(strstr(taken,searched)!=NULL)        {            printf("Appearance!!");        }         else             printf ("No appearance");         }     fclose(ptr);     return 0; }

27th Mar 2020, 10:53 PM
Daniel Brodowski
Daniel Brodowski - avatar
1 Odpowiedź