Hi community,
I am testing the lseek & write & read, and I write the code like this:


/*
    lseek_test.c
        Test the lseek
    Wen Yi
*/
#include <unistd.h&gt;
#include <fcntl.h&gt;
int main()
{
&nbsp;&nbsp; &nbsp;int fd = 0;
&nbsp;&nbsp; &nbsp;char buffer[16] = {};
&nbsp;&nbsp; &nbsp;write(STDIN_FILENO, "Hello world\n", sizeof("Hello 
world\n"));
&nbsp;&nbsp; &nbsp;lseek(STDIN_FILENO, 0, SEEK_SET);
&nbsp;&nbsp; &nbsp;read(STDIN_FILENO, buffer, sizeof(buffer));
&nbsp;&nbsp; &nbsp;write(STDIN_FILENO, buffer, sizeof(buffer));
&nbsp;&nbsp; &nbsp;return 0;
}


And I run the program ("Something Input" is my input content)



[beginnerc@bogon ???? C????]$ gcc lseek_test.c
[beginnerc@bogon ???? C????]$ ./a.out
Hello world
Something Input
Something Input
[beginnerc@bogon ???? C????]$ 



I really don't know, why the buffer's content not be "Hello world\n"? (I use 
the lseek to move the cursor to the beginning region)


Can someone give me some advice?
Thanks in advance!


Yours,
Wen Yi

Reply via email to