So it looks like this Ive got a file named "b.txt" created by me in windows and i want to read from it and print it on screen thats it and i didn't know it would be so complicated.
:shrug:
#include <stdio.h>
int main(void)
{
FILE *file = fopen("b.txt", "r");
if ( file )
{
char line[BUFSIZ];
while ( fgets(line, sizeof line, file) )
{
fputs(line, stdout);
}
fclose(file);
}
return 0;
}
[edit]BTW:1. EOF is a constant, it is equal to -1. It never changes.Don't concern yourself with any value defined by an implementation (such as -1). It might be highly likely (certainly at this point) that it is different, but it can be any negative integral value.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
EOF is not a character nor a value that exists at the end or middle of a file. It is a macro defined as an int with a negative value. It is a return value of functions that perform read operations (fgetc() and getchar()).
For example, The prototype of fgets() is
char *fgets(char *s, int n, FILE *stream);
The return code of fgets() is NULL when an error occours. The EOF is considered to be an ERROR!
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241