结构体和指针问题
发布网友
发布时间:2022-08-17 17:47
我来回答
共3个回答
热心网友
时间:2023-04-30 20:14
我用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)
{
SCHOOL* p=h;
printf ("*****name serial male female*****\n");
while(p!=NULL){
printf("%6s%6d%6d%6d\n",p->name,p->serial ,p->male,p->female);
p=p->next;
}
}
main ()
{
SCHOOL* head;
head=create();
print(head);
}
热心网友
时间:2023-04-30 20:15
把编译错误提示发出来先
热心网友
时间:2023-04-30 20:15
的确有点多
我看到多了个","
int型没有返回值.