fseek()

  原型:int fseek(FILE *stream, long int offset, int whence)
  
  参数解释:
      FILE *stream - 文件流,要打开的文件指针
      long int offset - 一个长整型数据类型 offset 表示偏移量,偏移字节数  
      int whence - 起始位置(从这开始偏移)
             【SEEK_SET:0,文件开头;SEEK_END:2,文件末尾;SEEK_CUR:1,文件指针当前位置】


  注:fseek 受文件的打开方式影响,
    如以 r+,打开文件的指针指向文件开头;
    以 a/a+ 打开文件的指针在文件尾部,fseek 移动文件指针无效

  例子:
    *fseek 与 fwrite 结合使用
     int size = sizeof(student);
        int offset = (SN - 1)*size;
        fseek(file, offset , SEEK_SET);
        fwrite(&newStd,sizeof(student),1,file);
    

猜你喜欢

转载自www.cnblogs.com/floakss/p/10585031.html