写了一个关于fprintf的程序,总是失败,不知是什么原因:
#include<stdio.h>
int main(void)
{
FILE *fp;
int i,j,k;
char ch;
fp=fopen("666.txt","a+");
if(fp==NULL)
printf("Open is failed!");
fscanf(fp," %d %d %c",&i,&j,&ch);
printf("**the ijch is : %d %d %c",i,j,ch);
k=fprintf(fp,"**the ijch is : %d %d %c",i,j,ch);
printf("the K is %d.\n",k);
fclose(fp);
return 0;
}
这里的 i j ch 分别是 556 778 s ,程序运行的结果如下:
即使将程序调整简单点,
#include<stdio.h>
int main(void)
{
FILE *fp;
int i,j,k,m=226;
char ch;
fp=fopen("666.txt","a+");
if(fp==NULL)
printf("Open is failed!");
fscanf(fp," %d %d %c",&i,&j,&ch);
printf("**the ijch is : %d %d %c",i,j,ch);
k=fprintf(fp,"%d",m);
printf("the K is %d.\n",k);
fclose(fp);
return 0;
}
K都是-1,写入都是失败的。 我没看出是哪里出错了,请指点。