|
我写了一个程序
void greatfile()
{
FILE *fp;
char namefile[20];
printf("\n在学号里输入0,便可以退出\n");
printf("\n请输入文件名:");
scanf("%s",namefile);
fp = fopen(namefile,"a+");
for (;;)
{
for (;;)
{
printf("\n请输入学号:");
scanf("%d",&stu.num);
if (stu.num == 0) break;
printf("\n请输入姓名:");
scanf("%s",&stu.name);
printf("\n请输入成绩:");
scanf("%d",&stu.score);
fwrite(&stu,sizeof(struct student),1,fp);
}
fclose(fp);
if (stu.num == 0) break;
}
printf("\n学号 姓名 成绩\n");
fp = fopen(namefile,"a+");
while (!feof(fp))
{
fread(&stu,sizeof(struct student),1,fp);
printf("%-10ld%-10s%-10ld\n",stu.num,stu.name,stu.score);
}
fclose(fp);
}
void search()
{
int num;
for(;;)
{
printf("\n================");
printf("\n1.按姓名查询");
printf("\n2.按学号查询");
printf("\n0.退出");
printf("\n================");
printf("\n请选择:");
scanf("%d",&num);
switch (num)
{
case 1: searchname();
break;
case 2: searchnum();
break;
}
if (num == 0) break;
}
}
为什么每次输入后,最后一组数据,都复制了一片.
郁闷阿!!!! :-( :-( :-( :-( :-( :-( :-( |
|