此程序运行成功但是有多余的字符出现,我根本没输入的怎么也显示出来了,怎么回事?
#include<stdio.h>
struct beng{
char type[12];
int num[4];
int round[3];
int press[3];
int angle[3];
}data[4];
main()
{
FILE *fp;
char ch;
int i,key;
if((fp=fopen("c:\\WIN-TC\\projects\\stu_list.txt","wb+"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
printf("input the data:");
for(i=0;i<4;i++)
{ scanf("%s%4d%3d%3d%3d",data[i].type,&data[i].num,&data[i].round,&data[i].press,&data[i].angle);
fwrite(&data[i],sizeof(struct beng),1,fp); }
rewind(fp);
printf("\ntype number state.round state.press state.angle\n");
for(i=0;i<4;i++)
{fread(&data[i],sizeof(struct beng),1,fp);
printf("%12s%4d%4d%4d%4d\n",data[i].type,data[i].num,data[i].round,data[i].press,data[i].angle); }
fclose(fp);
getch();
}