文件随机读写

来源:百度知道 编辑:UC知道 时间:2024/05/27 23:41:46
i是变量
fseek(fp,i*sizeof(struct student_type),1,fp);

i*sizeof(struct student_type)具体说明是什么

fseek(fp,i*sizeof(struct student_type),1,fp);
这个写错了,应该是:
fseek(fp,i*sizeof(struct student_type),1);

fseek
功 能: 重定位流上的文件指针
用 法: int fseek(FILE *stream, long offset, int fromwhere);
描 述: 函数设置文件指针stream的位置。如果执行成功,stream将指向以fromwhere为基准,偏移offset个字节的位置。如果执行失败(比如offset超过文件自身大小),则不改变stream指向的位置。
返回值: 成功,返回0,否则返回其他值

i*sizeof(struct student_type)标志的是偏移量,
这一行代码的作用是将当前的文件指针fp,偏移i*sizeof(struct student_type)个字节的位置。