|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- //成绩录入模块
- create()
- {
- FILE *fp;
- STUDENT stud;
- int i, stu_c;
- if ((fp = fopen("cj1.dat", "wb+")) == NULL)
- {
- printf("file open error!\n");
- exit(1);
- }
- system("cls");
- printf("please input students total counts:");
- scanf("%d%*c", &stu_c);
- printf("input %d students info\n", stu_c);
- for (i = 1;i <= stu_c;i++)
- {
- printf("input NO%d student information:\n", i);
- printf("Number:");
- //gets(stud.num);
- scanf("%[^\n]%*c",stud.num);
- printf("Name:");
- //gets(stud.name);
- scanf("%[^\n]%*c",stud.name);
- printf("3 scores(separato:):");
- scanf("%f,%f,%f%*c", &stud.score[0], &stud.score[1], &stud.score[2]);
- stud.score[3] = (stud.score[0] + stud.score[1] + stud.score[2]) / 3;
- fwrite(&stud, sizeof(STUDENT), 1, fp);
- }
- fclose(fp);
- return 0;
- }
复制代码
调试结果
please input students total counts:3
input 3 students info
input NO1 student information:
Number:001
Name:aaa
3 scores(separato:):30 50 70
input NO2 student information:
Number:Name:002
3 scores(separato:):40 10 20
input NO3 student information:
Number:Name:003
3 scores(separato:):
第二次和第三次输出的时候number跟name一起出来了,只能接收一个值,这个地方第一次通过了不知道怎么处理
|
|