一条简单的c语言题,不知道错在哪?

来源:百度知道 编辑:UC知道 时间:2024/05/30 04:49:32
#include"stdio.h"
main()
{FILE *fp;
char name[30];
long num;
float score;
fp=fopen("text12.txt","w");
if(fp==NULL)
{printf("can't open the file!");
getch();
exit(0);}
printf("please enter the name.num and the score:\n");
scanf("%s%l%f",name,&num,&score);
while(strlen(name)>1);
{fprintf(fp,"%s%l%f",name,num,score);
printf("please enter the name.num and the score:\n");
scanf("%s%l%f",name,&num,&score);}
fclose(fp);
}

文件格式化输入,不知道为什么进不了循环。
while(strlen(name)>1); 自己粗心多加了,但去掉分号后,输入第一个记录后却重复显示了3个please enter the name.num and the score:,又错在哪了???还有打开文件text12.txt看,结果输进去的是:hdfhd%l%f156416%l%f99.5%l%f,,晕这么多错,请高手们指点下

scanf("%s%l%f",name,&num,&score);
中%l应该时%ld
fprintf(fp,"%s%l%f",name,num,score);一样

#include"stdio.h"
main()
{FILE *fp;
char name[30];
long num;
float score;
fp=fopen("text12.txt","w");
if(fp==NULL)
{printf("can't open the file!");
getch();
exit(0);}
printf("please enter the name.num and the score:\n");
gets(name);
scanf("%ld%f",&num,&score);
while(strlen(name)>1)
{fprintf(fp,"%s%ld%f",name,num,score);
printf("please enter the name.num and the score:\n");
getchar();
gets(name);
scanf("%ld%f",&num,&score);
}
fclose(fp);
}

while(strlen(name)>1);
该语句后去掉分号,试试吧。
给分啊!