[7] Linux network programming standard IO's fseek

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/zztingfeng/article/details/90574071

Modifying the file stream read offset

fseek() 和文件IO中的 lseek() 类似,用于修改文件流读写的偏移量

int fseek(FILE *stream, long offset, int whence);

参数:FILE *stream: 指向文件的文件指针
    long offset : 偏移量移动的距离
    int whence  : 偏移量的基址
                    - SEEK_SET 文件开始处
                    - SEEK_CUR 文件当前位置
                    - SEEK_END 文件结束处
返回值:修改偏移量成功返回0, 修改偏移量失败返回-1
当 whence 是 SEEK_CUR 或 SEEK_END 时, offset 可正负。

Code:

#include <stdio.h>

int main ()
{
   FILE *fp;

   fp = fopen("file.txt","w+");
   fputs("This is runoob.com", fp);
  
   fseek( fp, 10, SEEK_SET );
   fputs(" C Programming Langauge", fp);
   fclose(fp);
   
   return(0);
}

 

Guess you like

Origin blog.csdn.net/zztingfeng/article/details/90574071