char * file = malloc(buffer);
assert(file != 0);
char str[20];
snprintf(file, buffer, "%s/%s", newestDirName, fileInDir->d_name);
FILE * input = fopen(file, "r"); // read
fseek(input, 0, SEEK_END);
fgets(str, 20, input);
printf("str = %s \n", str);
The file I am reading from has the last line:
ROOM TYPE: END_ROOM
Why isn't str storing "ROOM TYPE: END_ROOM
"
I thought fseek(input, 0, SEEK_END)
gets the last line with the cursor starting at the leftmost position of the last line. Is this wrong?
I thought fgets(str, 20, input)
gets 20 characters from input and puts it into str
which is a char *
variable.
But I get gibberish for str's value when I print str
:
str = ▒▒As=