鱼生富贵 2022-02-09 10:36 采纳率: 97.4%
浏览 88
已结题

建立一个链表存储学生信息。


#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(Student)
typedef struct 
{
    char no[8];//8位学号
    char name[20];//姓名
    int price;//成绩
    Student * next;
}Student;
int main()
{
    Student* Build_List();
    void Print(Student * head);

    Student * head;
    //根据指定学生个数,逐个输入学生信息
    head = Build_List();
    //逐个显示学生表中所有学生的相关信息
    Print(head);
    //根据姓名进行查找,返回此学生的学号和成绩
    return 0;
}
Student* Build_List()
{
    int n;
    Student* head, * p1, * p2;
    head = NULL;
    p1 = p2 = (Student*)malloc(LEN);
    scanf_s("%s", p1->no, 8);
    scanf_s("%s", p1->name, 20);
    scanf_s("%d", &p1->price);
    while (p1->no != 0)//p1->no==0标志输入结束,链表建立完成。
    {
        n = n + 1;
        if (n == 1)
            head = p1;
        else
            p2->next = p1;
        p2 = p1;
        p1 = (Student*)malloc(LEN);
        scanf_s("%s", p1->no, 8);
        scanf_s("%s", p1->name, 20);
        scanf_s("%d", &p1->price);
    }
    p2->next = NULL;
    return head;
}
void Print(Student* head)
{
    Student* p;
    p = head;
    printf("-------------------------Student List-------------------------\n");
    printf("NO.       NAME          SCORE\n");
    while (p != NULL)
    {
        printf("%8s%10s%5d\n", p->no, p->name, p->price);
        p = p->next;
    }
}

img

代码我放这了,这是怎么回事啊

  • 写回答

2条回答 默认 最新

  • jianyue--- 2022-02-09 15:19
    关注

    typedef struct
    {
    char no[8];//8位学号
    char name[20];//姓名
    int price;//成绩
    Student * next;//简单点说,至此Student 还没有定义 不能使用,Student 出现在后边,用不上。
    }Student;

    typedef struct Student //起个名字,不要匿名,以后要用
    {
    char no[8];//8位学号
    char name[20];//姓名
    int price;//成绩
    struct Student* next;
    }Student;

    typedef struct stu //起个名字,不要匿名,以后要用
    {
    char no[8];//8位学号
    char name[20];//姓名
    int price;//成绩
    struct stu* next;//编译cpp 代码时stu* next;也可以
    }Student;

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

报告相同问题?

问题事件

  • 系统已结题 2月17日
  • 已采纳回答 2月9日
  • 创建了问题 2月9日

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序