编译错误,为什么 #include<stdio.h> #include<stdlib.h> struct student { int n;char name[
解决时间 2021-02-12 00:15
- 提问者网友:火车头
- 2021-02-11 06:01
编译错误,为什么
#include
#include
struct student
{
int n;char name[100];
int score;
struct student *next;
};
int main()
{
struct student *head,*p,*q,a;
int i=3;
head=NULL;
for(p=head;i>0;i--,p=p->next)
scanf("%d%s%d",&p->n,p->name,&p->score);
p->next=NULL; scanf("%d%s%d",&a.n,a.name,&a.score);
for(p=head,q=p->next;q!=NULL;){
if(q->n>a.n){
p->next=&a;
p=p->next;
p->next=q;
}
p=p->next;q=q->next;
}
for(p=head;p->next!=NULL;p=p->next)
printf("%d\n%s\n%d\n",p->n,p->name,p->score);
}
最佳答案
- 五星知识达人网友:鸠书
- 2021-02-11 07:06
#include
struct student//////////结构体定义
{int no;
float grade;
struct student *next;};
int n;
struct student*head,*p;
struct student*creat()//////////定义输入函数
{
struct student*head;
struct student*p1,*p2;
n=0;
p1=p2=(struct student*)malloc(sizeof(struct student)); //这里要加强制转换
scanf(" %ld,%f",&p1->no,&p1->grade);
head=NULL;
while(p1->no!=0)
{n=n+1;
if(n==1)
head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(sizeof(struct student));//这里要加强制转换
scanf(" %ld,%f",&p1->no,&p1->grade);//sco改为grade
}
p2->next=NULL;
全部回答
- 1楼网友:舊物识亽
- 2021-02-11 07:42
int n ; 学号/编号
char name[10] ; 姓名
int score ; 分数
struct student st[n]; 定义n个学生结构体变量
scanf(“%d%s%d”, &st[i].n , st[i].name, &st[i].score) ;依次输入学生的学号,姓名与分数
我要举报
大家都在看
推荐资讯