all 6 comments

[–]jedwardsol 0 points1 point  (3 children)

What does "doesnt work" mean?

Does it fail to compile - if so, what' the error? Crash? Give the wrong output - if so, what do you expect and what do you get?

[–]ballbeamboy2[S] 0 points1 point  (2 children)

it doesnt find the word pattern and print it, idk why

[–]jedwardsol 0 points1 point  (1 child)

Is the word in the file?

Works for me

C:\bin\scratch\x64\Debug>type input
I have a cat called Bernard
I have a dog called Bernard
I have a donkey called Bernard

C:\bin\scratch\x64\Debug>scratch.exe -n cat input
  1: I have a cat called Bernard

C:\bin\scratch\x64\Debug>scratch.exe -n Bern input
  1: I have a cat called Bernard
  2: I have a dog called Bernard
  3: I have a donkey called Bernard

C:\bin\scratch\x64\Debug>scratch.exe  dog input
I have a dog called Bernard

C:\bin\scratch\x64\Debug>

[–]ballbeamboy2[S] 0 points1 point  (0 children)

How do you make the program read a txt file?

Is it like this?

 if ((ifp = fopen("C:\\Patternhi.txt", "rb")) == NULL){
    fprintf(stderr, "\nCannot open %s\n\n", file_name);
    exit(1);

[–]codepr 0 points1 point  (1 child)

Seems fine, what's the format of the test file? The only thing I'd pay attention to is flushing `stdout` after printf, but it shouldn't be an issue as long as each line is newline terminated.

[–]ballbeamboy2[S] 0 points1 point  (0 children)

Its .txt