零K沁雪


私信TA

用户名:qczl

访问量:74721

签 名:

零K沁雪

等  级
排  名 40
经  验 12025
参赛次数 3
文章发表 35
年  龄 0
在职情况 在职
学  校
专  业

  自我简介:

TA的其他文章

解题思路:

1、使用结构体指针存储学生信息

2、输入数据长度后使用malloc分配存储空间

注意事项:

参考代码:

#include<stdio.h>
#include<malloc.h>

typedef struct _student_info_
{
	char s_id[16];        //学号
	char s_name[32];      //姓名
	int s_score[3];       //三科成绩
}student_info;

void input(student_info *L)
{
	scanf("%s %s %d %d %d", L->s_id, L->s_name, &(L->s_score[0]), &(L->s_score[1]), &(L->s_score[2]));
}

void print(student_info *L)
{
	printf("%s,%s,%d,%d,%d\n", L->s_id, L->s_name, L->s_score[0], L->s_score[1], L->s_score[2]);
}

int main()
{
	student_info *list;
	int n = 0, i = 0;
	scanf("%d", &n);
	while(getchar() != '\n')
		continue;

	if(n > 0 && n < 100)
		list = (student_info *)malloc(sizeof(student_info)*n);
	else
		return 0;
	for(i = 0; i < n; i++)
	{
		input(&list[i]);
		//一行一行获取,忽略一行多余的数据
		while(getchar() != '\n')
			continue;
	}
	for(i = 0; i < n; i++)
	{
		print(&list[i]);
	}
	free(list);
	return 0;
}


 

0.0分

60 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区

我感觉两个这个
while(getchar() != '\n')
        continue;
有没有都一样
2019-09-15 16:39:58
为啥定义的list指针,却可以使用 list【i】呢
2019-09-05 18:27:59
&(L->s_score[0])前面可以不加&吗,L->s_score[0]不就表示score[0]的地址吗
2019-08-14 17:46:12
为什么学号不能定义为int型
2019-05-30 11:32:32
编译没报错,运行错误,这么回事呀,求大神看看,解释一下好不
#include<stdio.h>

struct student_information
{ 
	char student_id[16];
	char student_name[16];
    int chinese;
	int mathematics;
	int english;
};

void input(struct student_information * p,int stu_num)
{    int i;
     for(i=0;i<stu_num;i++)
         scanf("%s %s %d %d %d",
			  (p+i)->student_id,(p+i)->student_name, 
			  &(p+i)->chinese,&(p+i)->mathematics,&(p+i)->english);   
}
 

void print(struct student_information *p,int std_num)
{   
	int i;
	for(i=0;i<std_num;i++)
        printf("%s,%s,%d,%d,%d",p[i].student_id,p[i].student_name,
		        p[i].chinese,
2019-03-11 11:23:09
哪里错啊
#include "stdio.h"
#include "malloc.h"
typedef struct Student
{
	char id[10];
	char a[10];
	int ch;
	int ma;
	int en;
}Student;
void input(int n,Student *li)
{
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%s %s %d %d %d",&li->id,&li->a,&li->ch,&li->ma,&li->en);
	}
}
void print(Student *li)
{
	printf("%s,%s,%d,%d,%d\n",li->id,li->a,li->ch,li->ma,li->en);
}
void main()
{
	Student *list;
    int n,i;
    scanf("%d",&n);
    if(n>0&&n<100)
        list = (Student *)malloc(sizeof(Student)*n);
    for(i=0;i<n;i++)
    {
    	input(n,&list[i]);
    }
    for(i=0;i<n;i++)
    {
    	print(&list[i]);
2019-02-24 17:24:26
请问while(getchar() != '\n')
        continue;
这两行具体有什么作用,可以不加吗?
2019-02-24 17:02:14
#include<stdlib.h>
#include<stdio.h>
struct stu{
	char xuehao[20];
	char name[20];
	int a;
	int b;
	int c;
	struct stu *next;
};
struct stu *input(int n){
	struct stu *head,*pb,*pf,*p;
	for(int i=0;i<n;i++){
		pb=(struct stu *)malloc(sizeof(struct stu));
		scanf("%s%s%d%d%d",&pb->xuehao,&pb->name,&pb->a,&pb->b,&pb->c);
		if(i==0){
			pf=head=pb;
		}else{
			pf->next=pb;
			pb->next=NULL;
			pf=pb;
		}
	}
	return(head);
}
void print(struct stu *head){
	struct stu *p;
	for(p=head;p!=NULL;p=p->next){
		printf("%s,%s,%d,%d,%d\n",p->xuehao,p->name,p->a,p->b,p->c);
	}
}
void main(){
	int n;
	scanf("
2019-02-19 20:41:55