char x[3];
char buff, c;
x[0]='y';
int offset, i;
int fd;
fd = open("test1.txt", O_RDONLY);
if(fd==-1){ printf("Error on fopen."); exit(1); }
offset = lseek(fd, 1, SEEK_END);
printf("Size of file is: %d. \n", offset);
for(i=offset-1; i>=0; i--)
{
c = read(fd, &buff, 1);
printf("The character is: %c. \n", c);
}
close(fd);
运行这个给了我。
Size of file is: 6.
The character is: .
The character is: .
The character is: .
The character is: .
The character is: .
The character is: .
测试文件只包含单词“TEST”。我希望能够向后打印单词。