I'm trying to read 4 characters from a file, and then output them to the screen.
the file contains:
This is my basic code:
char *filename = "file.txt";
FILE *fp = fopen(filename, "r");
fread (line, sizeof(char), 4, fp);
line = '\0';
printf("line: %s\n", line);
The output is abcdW
Why is the last character of my output always screwed up?
My goal is to (eventually) read in 50 characters, print to screen, then read in another
50 characters, etc.
I just can't figure out why the 5th character which is supposed to be null, gets printed
all scewed up.