Originally Posted by
ofnuts
The file descriptor contains the length in bytes.
Thans ofnuts.
But, I need some more help here. I've used the EOF inside a C program few times that I've almost started to believe it's what signals the end of the road. Consider the code below, assuming "test.txt" contains just numbers from 0-9. That's it, no newline, just numbers.
Code:
#include <stdio.h>
int main(void)
{
FILE* fp;
char c;
fp = fopen("test.txt","r");
while(1)
{
c = getc(fp);
if(c == EOF)
{
printf("EOF == [%d] reached, breaking now\n",c);
break;
}
printf("read : [%c]==[%d]\n",c,c);
}
return 0;
}
And this is the output
Code:
read : [0]==[48]
read : [1]==[49]
read : [2]==[50]
read : [3]==[51]
read : [4]==[52]
read : [5]==[53]
read : [6]==[54]
read : [7]==[55]
read : [8]==[56]
read : [9]==[57]
read : [
]==[10]
EOF == [-1] reached, breaking now
This basically shows me that there are two characters which I haven't entered - 1.linefeed(ascii == 10) and 2.EOF, I guess(value == -1)
Can you tell me something about each of these two characters ? I thought about it a bit and came up with these possible answers.
1.(the linefeed) - as you said, probably, the text editor inserts this. But why ?
2.I'm basically interested in knowing when the EOF is inserted.
- Is it like, as you said, the inode tells the filesize, after which an EOF character(-1) is inserted so that C programs know when to stop reading ? OR
- Is it like, newline and EOF are two characters that are always there in any file, by default, and these are concatenated to the file contents when you do a :wq! in vi. ?
Thanks.
Bookmarks