I can't understand how EOF works and HOW does my pc know the size of a file.
For example I made 3 files, test0, test1 and test2. I created test0 and test1 in this way:
int main(void) {
/* */
FILE* fp0 = fopen("/home/kevin/eclipse-workspaceC/FileMangment/src/test0", "w+");
FILE* fp1 = fopen("/home/kevin/eclipse-workspaceC/FileMangment/src/test1", "w+");
if (!fp0 || !fp1) {
fprintf(stderr, "file pointer points to NULL\n");
return 1;
}
fprintf(fp0, "abcd");
fprintf(fp1, "abcd\n");
fclose(fp0);
fclose(fp1);
return 0;
}
Then I created test2 with, right click -> new documents and inside the file I wrote:
abcd
Without a space nor a new line at the end.
Then on the bash I ran the command: wc -c test*; file test*
and the output:
4 test0
5 test1
5 test2
14 total
test0: ASCII text, with no line terminators
test1: ASCII text
test2: ASCII text
When I go to watch the files with gedit they seems identical(no new lines founded).
I know that \n is newline and not EOF (And I really can't understand what is this this EOF), so HOW does my pc know when the file ends? If the disk block size is 4K why does it stop after the correct number of bytes and it does not continue to read whatever is comes after?
Why do I see tons of codes that parses a file in this way:
while((c=fgetc(infile))!=EOF){
putchar(c);
}
So this MEANS that there is SOMEWHERE a character called (EOF)??????? But I can't find it in ascii table. And I found that is value is -1.... Very very very confusing...
Is my pc parsing every file for know is size or it's written somewhere?
Somewhere in my computer the must be:
your file at position xyz has the size of blahblah...
So WHERE is this place? or what should I google? Because I Googled something like 3Gozzilion of things like: where is my file size stored ecc... and did't find anything. I Just want to know where is this information stored.