whiteky 2021-12-23 09:34 采纳率: 100%
浏览 36
已结题

为什么这个代码姓名不能输入三个及以上个汉字?

姓名不能输入过多字符,输入过多字符时程序会结束



```c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

struct Student         //自定义结构体
{
    int      number;
    char     name[100];
    int      jidao;
    int      math;
    int      eng;
    int      com;
}stu[40];
int main()    //输入学生信息
{
    int n = 0;
    int i = 0;
    char  c;
    do
    {
        printf("\t\t\t学号:");
        scanf_s("\t\t\t%d", &stu[n + i].number);
        printf("\t\t\t姓名:");
        scanf_s("\t\t\t%s", &stu[n + i].name,sizeof(50));
        printf("\t\t\t计导分数:");
        scanf_s("\t\t\t%d", &stu[n + i].jidao);
        printf("\t\t\t高数分数:");
        scanf_s("\t\t\t%d", &stu[n + i].math);
        printf("\t\t\t外语(日语/英语)分数:");
        scanf_s("\t\t\t%d", &stu[n + i].eng);
        printf("\t\t\tC语言分数:");
        scanf_s("\t\t\t%d", &stu[n + i].com);
        i++;
        printf("\t\t\t继续录入成绩吗?\n");
        printf("\t\t\t请输入‘y’继续,或's'停止");
        scanf_s("\t\t\t%c", &c,10);
    } while (c == 'y');
    return (i + n);
}

```

  • 写回答

3条回答 默认 最新

  • qzjhjxj 2021-12-23 10:30
    关注

    printf("\t\t\t姓名:");
    scanf_s("\t\t\t%s", stu[n + i].name, sizeof(stu[0].name));
    //scanf_s("\t\t\t%s", &stu[n + i].name, sizeof(50));

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 12月31日
  • 已采纳回答 12月23日
  • 创建了问题 12月23日

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题