这个c程序怎么改
答案:1 悬赏:60 手机版
解决时间 2021-02-13 18:51
- 提问者网友:回忆在搜索
- 2021-02-13 03:25
这个c程序怎么改
最佳答案
- 五星知识达人网友:煞尾
- 2021-02-13 03:55
void print(struct student *q)//函数定义的第二个参数是指针
print(insertT(p,&stud));//指针接受的是地址,所以在stud前加上&,以表示stud的地址
#include
#include
#define LEN sizeof(struct student)
#define N 10
struct student
{
long num;
char name[10];
float score[3];
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head,*p1,*p2;
int i;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%s",&p1->num,&p1->name);
for(i=0;i<3;i++)
scanf("%f",&p1->score[i]);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%s",&p1->num,&p1->name);
for(i=0;i<3;i++)
scanf("%f",&p1->score[i]);
}
p2->next=NULL;
return(head);
}
void main()
{
struct student *insertT(struct student *head,struct student *stud);
void print(struct student *q);
struct student stud,*p;
int i;
printf("输入要插入的学生数据:\n");
scanf("%ld,%s",&stud.num,&stud.name);
for(i=0;i<3;i++)
scanf("%f",&stud.score[i]);
p=creat();
print(insertT(p,&stud));//指针接受的是地址,所以在stud前加上&,以表示stud的地址
}
struct student *insertT(struct student *head,struct student *stud)
{
struct student *p0,*p1;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
head=p0;
p0->next=p1;
}
n++;
return(head);
}
void print(struct student *q)
{
struct student *p;
int i;
p=q;
if(p!=NULL)
do
{
printf("%ld,%s",p->num,p->name);
for(i=0;i<3;i++)
printf("%f",p->score[i]);
p=p->next;
}while(p!=NULL);
}
print(insertT(p,&stud));//指针接受的是地址,所以在stud前加上&,以表示stud的地址
#include
#include
#define LEN sizeof(struct student)
#define N 10
struct student
{
long num;
char name[10];
float score[3];
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head,*p1,*p2;
int i;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%s",&p1->num,&p1->name);
for(i=0;i<3;i++)
scanf("%f",&p1->score[i]);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%s",&p1->num,&p1->name);
for(i=0;i<3;i++)
scanf("%f",&p1->score[i]);
}
p2->next=NULL;
return(head);
}
void main()
{
struct student *insertT(struct student *head,struct student *stud);
void print(struct student *q);
struct student stud,*p;
int i;
printf("输入要插入的学生数据:\n");
scanf("%ld,%s",&stud.num,&stud.name);
for(i=0;i<3;i++)
scanf("%f",&stud.score[i]);
p=creat();
print(insertT(p,&stud));//指针接受的是地址,所以在stud前加上&,以表示stud的地址
}
struct student *insertT(struct student *head,struct student *stud)
{
struct student *p0,*p1;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
head=p0;
p0->next=p1;
}
n++;
return(head);
}
void print(struct student *q)
{
struct student *p;
int i;
p=q;
if(p!=NULL)
do
{
printf("%ld,%s",p->num,p->name);
for(i=0;i<3;i++)
printf("%f",p->score[i]);
p=p->next;
}while(p!=NULL);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯