0
Follow
0
View

The list traverses and doesn't print out what's inside

dzqfengxiang 注册会员
2023-02-27 23:38
< div class = "md_content_show e397 data - v - 3967" = "" >

good

djnandy 注册会员
2023-02-27 23:38
< div class = "md_content_show e397 data - v - 3967" = "" >

yes

evilrise 注册会员
2023-02-27 23:38
< div class = "md_content_show e397 data - v - 3967" = "" >

thanks for elder brother,

dy198528 注册会员
2023-02-27 23:38
< div class = "md_content_show e397 data - v - 3967" = "" >

this is directly to find the ChatGPT answered

diabloyq 注册会员
2023-02-27 23:38

This answer quotes ChatGPT

There are some obvious problems in your code that may cause the data in the linked list to not be printed correctly:

In the stu function, you should use the %s format controller instead of %d when you input a string using scanf.

In the addstu function, when you enter a string using scanf, you should precede the string with a space to eliminate the preceding newline character.

In the addstu function, when you enter a character using scanf, you should precede the character with a space to eliminate the preceding line break.

In the printfstu function, when you print the date and health code, you should put it in a brace to avoid formatting string errors.

Here are the addstu and printfstu functions that have been modified:

void addstu()
{
    //创建新的节点
    Node* pNewNode = (Node*)malloc(sizeof(Node));
    pNewNode->pNext = NULL;

    //头插法
    if (g_pHead == NULL)
    {
        g_pHead = pNewNode;
    }
    else
    {
        pNewNode->pNext = g_pHead;
        g_pHead = pNewNode;
    }
    printf("请输入学号\n");
    scanf("%d", &(pNewNode->stu.ID));

    printf("请输入姓名\n");
    scanf(" %s", pNewNode->stu.name);

    printf("请输入到校日期,例如:yyyy-mm-dd\n");
    scanf(" %s", pNewNode->stu.day);

    printf("请选择健康码类型,红码填A,黄码填B,绿码填C\n");
    scanf(" %c", &(pNewNode->stu.ma));

    printf("请选择返校方式(单选题)\nA火车/动车/高铁\nB飞机\nC自驾\nD其他\n");
    scanf(" %s", pNewNode->stu.fangshi);

    printf("请输入乘坐车次\n");
    scanf(" %s", pNewNode->stu.chaci);

    printf("请选择风险类型(单选题)\nA无\nB途径高风险地区\nC居住在高风险地区\nD密接高危人群\n");
    scanf(" %s", pNewNode->stu.leixing);

    printf("请输入途经城市(包括家和学校所在城市,城市间用空格分隔)\n");
    scanf(" %s", pNewNode->stu.tujing);

    printf("请输入最近一次做核酸时间,格式为:yyyy-nn-dd\n请选择最近一次核酸结果,-表示阴性,+表示阳性\n");
    scanf(" %s", pNewNode->stu.hesuanshijian);

    printf("学生信息录入完成\n");
}

void printfstu()
{
    printf(" ******************************************************************\n\n");
    printf(" * \t                           疫情防控管理系统              \t       *\n");
    printf("*\t学号\t姓名\t到校日期\t健康