结构体和指针问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 10:44:28
这是一道输入并输出学校参加运动会的详细信息,包括学校的编号,校名,参赛的男女人数,学校总人数,自己是初学指针,试着写了下面的程序,可是有好多错误,不知道怎么改,麻烦大家看看:
typedef struct school
{int serial;
char name[20];
int male;
int serial;
int female;
struct school *next;
}SCHOOL;
SCHOOL* creat()
{
SCHOOL *p1,*s,*h,;
int i,n;
puts("\nPlease input the number of shools n=:");
scanf("%d",&n);
h=(SCHOOL *) malloc(sizeof(SCHOOL));
for(i=0;i<n; i++)
printf("please input %d shools'information:\n") ;
h=NULL;
r=h;
for(i=0;i<n; i++)
{p1=(SCHOOL *) malloc(sizeof(SCHOOL));
r->link=p1 ;
r=p1;
scanf("%s%d%d%d",s->name,&s->serial ,&s->male,&s->female);
}
return(h);
}
void printf(SCHOOL*h )
{SCHOOL*p;
printf ("*****name serial male female*****\n");
p=h

我用TC试了一下,问题果然好多啊,你的问题实在太多了,有的地方好像还没改好,我只好做了鞋改动,你看看:
#include <stdio.h>
typedef struct school
{
int serial;
char name[20];
int male;
int female;
struct school *next;
}SCHOOL;

SCHOOL* create()
{
SCHOOL *head,*last,*p=NULL;
int i,n;
puts("\nPlease input the number of shools n=:");
scanf("%d",&n);
printf("please input shools'information:\n") ;

p=(SCHOOL*) malloc(sizeof(SCHOOL));
p->next=NULL;
scanf("%s%d%d%d",p->name,&(p->serial),&(p->male),&(p->female));

last=head=p;
for(i=1;i<n;i++){
p=(SCHOOL*) malloc(sizeof(SCHOOL));
scanf("%s%d%d%d",p->name,&(p->serial),&(p->male),&(p->female));
p->next=NULL;
last->next=p;
last=p;
}
return head;
}
void print(SCHOOL* h)
{