The system i am using is Linux.
Code:
#include<stdio.h>
#include<sys/stat.h>
#include<fcntl.h>
void main()
{
int rbytes,wbytes,fd1,local;
char buf[10],ch;
fd1=open("f3.txt",O_RDONLY,0);
local=lseek(fd1,0,SEEK_CUR);
printf("The start file pointer position:%d\n",local);
local=lseek(fd1,0,SEEK_END);
printf("End pointer position:%d\n",local);
local=lseek(fd1,-10,SEEK_END);
printf("-10 File pointer location:%d\n",local);
rbytes=read(fd1,buf,5);
buf[5]='\0';
printf("buf=%s\n",buf);
close(fd1);
}
Result:
The file's content of "f3.txt" is "123456789".
As we all know:
if the content is 123456789
the corresponding index is 012345678
The value of lseek(fd1,0,SEEK_END) should be equal to '9', instead of '10'(base on the explanation of SEEK_END: the offset to the end of file), which confuse me a lot. Why?
The image of file content:
And the result of command 'wc':