Yuli


私信TA

用户名:dotcpp0689202

访问量:54

签 名:

等  级
排  名 5214
经  验 1514
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 中山大学
专  业

  自我简介:

解题思路:

              1.利用结构体储存学生信息

              2.利用malloc 申请内存空间

              3.利用指针people 遍历内存信息并输出


注意事项:

               用getchar()去除' \n '

参考代码:

#include<stdio.h>

#include<malloc.h>

typedef struct _Student

{

    char num[10];

    char name[10];

    int Chinese;

    int Maths;

    int English;


}Student;

int main()

{   

    int n = 0;

    scanf("%d", &n);

    Student* people = (Student*)malloc(sizeof(Student) * n);

    for (int i = 0; i < n; i++)

    {

        scanf("%s %s %d %d %d", (people+i)->num, (people + i)->name, &(people + i)->Chinese, &(people + i)->Maths, &(people + i)->English);

        getchar();

    }

    for (int i = 0; i < n; i++)

    {

        printf("%s,%s,%d,%d,%d\n", (people + i)->num, (people + i)->name, (people + i)->Chinese, (people + i)->Maths, (people + i)->English);

    }

    free(people);

    return 0;

}


 

0.0分

3 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区