错哪里了?帮忙看一下,急!!!急!!! 20
#include<stdio.h>#include<malloc.h>#defineNULL0structstudent{charnum[8];charname[16];...
#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct student
{
char num[8];
char name[16];
int score;
struct student *next;
};
int n; /*n为全局变量*/
struct student *creat() /*定义函数*/
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(sizeof(struct student)); /*开辟第一个接结点*/
scanf("%s,%s,%d",&(p1->num),&(p1->name),&(p1->score));
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student)); /*再开辟下一个结点*/
scanf("%s,%s,%d",&(p1->num),&(p1->name),&(p1->score));
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("\nNow,Output date:\n");
p=head;
if(head!=NULL)
do
{
printf("%s,%s,%d",p->num,p->name,p->score);
p=p->next; /*指向下一个结点*/
}while(p!=NULL);
}
void main()
{
struct student *creat();
void print(struct student *head);
struct student *head;
head=NULL;
head=creat();
print(head);
} 展开
#include<malloc.h>
#define NULL 0
struct student
{
char num[8];
char name[16];
int score;
struct student *next;
};
int n; /*n为全局变量*/
struct student *creat() /*定义函数*/
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(sizeof(struct student)); /*开辟第一个接结点*/
scanf("%s,%s,%d",&(p1->num),&(p1->name),&(p1->score));
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student)); /*再开辟下一个结点*/
scanf("%s,%s,%d",&(p1->num),&(p1->name),&(p1->score));
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("\nNow,Output date:\n");
p=head;
if(head!=NULL)
do
{
printf("%s,%s,%d",p->num,p->name,p->score);
p=p->next; /*指向下一个结点*/
}while(p!=NULL);
}
void main()
{
struct student *creat();
void print(struct student *head);
struct student *head;
head=NULL;
head=creat();
print(head);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询