鱼C论坛

 找回密码
 立即注册
查看: 1910|回复: 5

c语言输出问题

[复制链接]
发表于 2019-8-19 08:57:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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一起出来了,只能接收一个值,这个地方第一次通过了不知道怎么处理

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-8-19 21:40:37 | 显示全部楼层
没人吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-8-19 22:32:09 | 显示全部楼层
建议把代码贴完整
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 2 反对 0

使用道具 举报

发表于 2019-8-20 22:23:27 | 显示全部楼层
         scanf("%[^\n]%*c",stud.num);  //这一行代码 ————你的结构体中定义的num是 int  还是int * ,如果是 int      ;建议改成:

scanf("%[^\n]%*c",&stud.num);
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-8-22 07:06:14 | 显示全部楼层
人造人 发表于 2019-8-19 22:32
建议把代码贴完整

只是这个模块问题。已经解决了,输入的时候没打逗号。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-8-22 07:08:37 | 显示全部楼层
Richard149 发表于 2019-8-20 22:23
scanf("%[^\n]%*c",stud.num);  //这一行代码 ————你的结构体中定义的num是 int  还是int *  ...

好的 已经解决了,输入的时候没打逗号
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-4 05:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表