关于fscanf和fprintf的简单操作,哪儿出错了啊?
#include <stdio.h>#include <string.h>
#include <stdlib.h>
struct student
{
char name[20];
int num;
char flag;
}stu[3];
void main()
{
FILE *fin;
FILE *fout;
char name[20];
int num;
char flag;
if((fin=fopen("fscanf.txt","r"))==NULL)
{printf("cannot open the file!\n");
exit (0);}
if((fout=fopen("fprintf.txt","w"))==NULL)
{printf("cannot open the file!\n");
exit (0);}
int i=0;
while(3==fscanf(fin,"%s%d%c",name,&num,&flag))
{
strcmp(stu[i].name,name);
stu[i].num=num;
stu[i].flag=flag;
fprintf(fout,"%s%d%c",stu[i].name,stu[i].num,stu[i].flag);
printf("%s %d %c\n",stu[i].name,stu[i].num,stu[i].flag);
i++;
}
}