esbo brings up a good point: what is the length of the longest word that you expect? There are ways to accomodate words of arbitrary length, but that might be a little too complex for you at the moment.
That said, even when you do know the expected maximum length, you should still write code to not overflow your string buffer should invalid input be entered with a word longer than expected.
Modifying esbo's example:
Code:
#include <stdio.h>
int main(void) {
FILE *file_pointer;
char input_buffer[200];
if ((file_pointer = fopen("all.txt", "r")) == NULL) {
puts("all.txt does not exist");
} else {
while (fscanf(file_pointer, "%199s", input_buffer) != EOF) {
printf("%s\n", input_buffer);
}
fclose(file_pointer);
}
return 0;
}
The "%199s" ensures that at most 199 characters will be put in the string, with the last reserved for the terminating null character. Note that with this approach the integer value denoting the number of words will also be read as a word. Perhaps you are supposed to read it first, create a dynamic array of strings with that value as the size, and only then proceed to read in the words into that array?