私信TA

用户名:chenqi

访问量:33880

签 名:

等  级
排  名 355
经  验 5107
参赛次数 0
文章发表 52
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

#include<stdio.h>
#include<string.h>

#define count_course 3

typedef struct
{
     char num[10];
     char name[10];
     int grade[count_course];
} Student;

Student* input(int std_num)
{
     int i,j;
     Student *ptr;    //定义结构体指针
     static Student std[100];
     for(i=0;i<std_num;i++)
     {    
          scanf("%s%s",&std[i].num,&std[i].name);
          for(j=0;j<count_course;j++)
          {
               scanf("%d",&std[i].grade[j]);
          }
     }
     ptr = std;
     return ptr;    
 
}

int print(Student *ptr,int std_num)
{
     int i,j;
     for(i=0;i<std_num;i++)
     {
          printf("%s,%s",(ptr+i)->num,(ptr+i)->name);//访问std[i]结构体
      for(j=0;j<count_course;j++)
      {
           printf(",%d",(ptr+i)->grade[j]);
      }
          printf("\n");
      }
}

int main()
{
    int N;
    Student *pStruct;
    scanf("%d",&N);
    pStruct = input(N);
    print(pStruct,N);
    return 0;
}
 

0.0分

0 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区