Whats the difference between this lseek, fseek, read, fread?

后端 未结 3 1157
无人共我
无人共我 2021-02-10 09:17

I am calling these functions:

unsigned blah[5];
lseek(0, 100, SEEK_CUR);
read(0, blah, sizeof(blah));

and

FILE *fr;
fr = fopen(         


        
3条回答
  •  误落风尘
    2021-02-10 10:11

    SEEK_CUR starts from the current position. That is why your first seek works when you are at the beginning of the file. To always seek from the beginning you need to use SEEK_SET instead of SEEK_CUR.

    0   SEEK_SET    The beginning of the file
    1   SEEK_CUR    The current position
    2   SEEK_END    The end of the file
    

提交回复
热议问题