Hello.
I'm working on a project that uses input redirection to read text from a file. Everything worked fine until I needed to search for a word that user inputs in a console...
So, something like this>
>program.exe < input.txt
and after this line my program asks the user 'Please input the word you want to search for in a document'. Now, when I try to scanf that word, program crashes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main()
{
char word[20], line[20];
char c;
printf("What word to search for?\n"); //it prints out this line and crashes
scanf("%[^\n]", word);
scanf("%s", word);
printf("Word we are searching for is: %s\n", word);
do {
c = fscanf(stdin,"%s",line); //i know this do-while works
//some other code
} while (c != EOF);
return 0;
}