I made a simple program that reads a file and prints the contents of the file to the output.
It prints the file contents to the output like it should, but there's a strange question mark at the end of it. I typed, ./prog foobar into the Terminal and it printed the following.Code:#include <stdio.h>
int main(int argc, char *argv[])
{
if (!argv[1])
{
printf("USAGE: %s [filename]\n", argv[0]);
return 1;
}
FILE *in = (fopen(argv[1], "r"));
char *file;
while (file != EOF)
{
file = fgetc(in);
printf("%c", file);
}
printf("\n");
return 0;
}
There is no question mark at the end of the foobar file. Is it printing the terminating null byte? Can someone explain this to me?Code:Hello World!
?