c语言 问题

这问题怎么解 请说明一下

#include"stdio.h"
#include"malloc.h"
typedef struct student
{int num;
float score;
struct student *link;
}stu;

stu *creat()
{stu *head;
stu *p1,*p2;
int n=0;
p1=p2=(stu *)malloc(sizeof(stu));
printf("input number and score:");
scanf("%d,%f, &p1->num1,&p1->score);
head=null;
while(p1->num!0)
{n=n+1;
if(n==1) head=p1;
else p2->link=p1;
p2=p1;
p1=(stu *)malloc(sizeof(stu));
scanf("%d,%f,&p1->num,&p1->score);
}
p2->link=null;
return(head);
}

#include"stdio.h"
#include"malloc.h"

struct student
{int num;
float score;
struct student *link;
}stu; //STU用处不大,可以不要.

struct student *creat(struct student stu) //链表传值问题.
{
struct student *head=NULL,*p1,*p2; //NULL要大写,你的P1,P2,STU是同级的,不能用stu *p1形式啊,只是P1是指向结点的指针,STU是是结构体变量.
int n=0;
p1=(struct student *)malloc(sizeof(stu));
printf("input number and score:");
scanf("%d%f", &p1->num,&p1->score); //你那有个小毛病,要特别注意啊.
while(p1->num!=0)
{

n=n+1;
if(n==1) {head=p1;p2=head; }
else //ELSE的括号问题
{
p2->link=p1;
p2=p1;
}
p1=(struct student *)malloc(sizeof(stu));
printf("input number and score:");
scanf("%d%f", &p1->num,&p1->score);
}
p2->link=NULL;
return(head);
}
你去这个网址看一下吧.我刚问了一个关于链表的问题.多看一下,你就明白了啊.
http://zhidao.baidu.com/question/73388679.html
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-10-30
你这个程序好多语法错误!
第2个回答  2008-10-30
怎磨没有输出 啊??
相似回答