最近用指针老出问题,最大的问题是,我不知道怎么出的问题.....

来源:百度知道 编辑:UC知道 时间:2024/06/22 16:23:23
#include <stdio.h>
#include <stdlib.h>
typedef struct studentes{
long number;
char name[20];
double course1,course2,course3;
struct studentes *next;
}student;

student *creat(int n) //n为学生人数
{
student *head,*p1,*p2;
p1=head=(student *)malloc(sizeof(student));
head->next=NULL;
for(int i=1;i<=n;i++)
{
p2=(student *)malloc(sizeof(student));
p2->next=NULL;
p1->next=p2;
p1=p2;
printf("第%d个同学的学号,姓名,课程1,课程2,课程3:\n",i);
scanf("%d,%s,%f,%f,%f",&p2->number,p2->name,&p2->course1,&p2->course2,&p2->course3);
}
p2->next=NULL;
return head;
}
void main()
{
student *head,*p;
head=creat(2);
p=head->next;
do{
printf("%6d,%s,%6d,%6d,%6d",p->number,*(p->name),p->course1,p->course2,p->course3);
p=p->next;
}

//大哥,我晕,搞了我N久,原来是你格式化输入输出有问题,下次小心一点呀。我这个能运行,你看看吧!
#include <stdio.h>
#include <stdlib.h>
typedef struct studentes{
long number;
char name[20];
double course1,course2,course3;
struct studentes *next;
}student;

student *creat(int n) //n为学生人数
{
student *head,*p1;
head=NULL;
for(int i=1;i<=n;i++)
{
p1=(student *)malloc(sizeof(student));
p1->next=head;
head=p1;
printf("第%d个同学的学号,姓名,课程1,课程2,课程3:\n",i);
scanf("%d%s%*c%Lf%Lf%Lf",&p1->number,p1->name,&p1->course1,&p1->course2,&p1->course3);
}
return head;
}
void main()
{
student *head,*p;
head=creat(2);
p=head;
do{
printf("%6d,%s,%6.2Lf,%6.2Lf,%6.2Lf",p->number,p->name,p->course1,p->course2,p->course3);
p=p->next;
}while(p!=NULL);
printf