#include<stdio.h>
int main()
{
FILE * fp;
char f[20];
char file[30];
//int *a[]={12,33,23,24,12};
char *str="hello,I am program!";
printf("please enter the city:");
scanf("%s",f);
sprintf(file,"/weather/%s.xml",f);
if((fp=fopen(file,"wr"))==NULL)
{
printf("open fail\n");
return -1;
}
if((fseek(fp,-3,SEEK_END))!=0);
{printf("seek fail\n");
close(fp);
return -1;
}
if((fwrite(str,sizeof(str),strlen(str),fp))==NULL)
{
printf("write fail\n");
close(fp);
return -1;
}
//close(fp);
return 0;
}
编译执行后 fseek fail 。。。。
linux环境下的 连if((fseek(fp,-3,SEEK_END))!=NULL);也试过了 我的本意是将光标移动到文件的倒三位置 然后在这个位置上写入新数据的