高手进来指点指点阿!谢谢先!
学完文件这章时自己编的一个练习题,有点问题:程序本身可以编译过去,但结果和我的想法有点差错:我原意只在屏幕上显示结果一次,可是运行时结果总显示两次,不知为何?望高手指点一二。下面是程序:#include <stdio.h>
#include <string.h>
main()
{FILE *fp;
long num;
int score,i;
char name[20];
fp=fopen("d:\\hit.txt","w");
printf("please input the data of the student\n");
for(i=1;i<=2;i++)
{scanf("%d,%s,%ld",&score,name,&num);
fprintf(fp,"%d,%s,%ld",score,name,num);}
fclose(fp);
fp=fopen("d:\\hit.txt","r");
for(i=1;i<=2;i++)
{fscanf(fp,"%d,%s,%ld",&score,name,&num);
printf("%d,%s,%ld",score,name,num);}
fclose(fp);
}