当我在文本中的某一行进行插入操作的时候,插入的内容存在了,但是它下面的内容怎么没有了?
#include <stdio.h>;
#include "err_exit.h"
struct record{
int uid;
char login[9];
};
char *logins[]={"user1","user2","user3","user4","user5"};
void putrec(FILE *fp,int i,struct record *r)
{
fseek(fp,(long)i*sizeof(struct record),0);
[color=red]fwrite((char *)r,sizeof(struct record),1,fp);[/color]
}
int main(void)
{
int i;
FILE *fp;
struct record rec;
if ((fp = fopen("datafile","tb"))==NULL)
err_exit("datafile");
for(i=4;i>;=0;i--)
{
rec.uid=i;
strcpy(rec.login,logins);
putrec(fp,i,&rec);
}
fclose(fp);
exit(0);
}
执行该程序后datafile文件是空的啊