基于c语言的数据结构程序设计 帮我看看错误在哪啊 不能运行啊

#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student //定义一个结构体变量struct Student
{int num;
char name[20];
float score;
struct Student *link;
};

struct Student *creat() //建立链表的函数
{
struct Student *h,*s;
int x;
char y[20];
float z;
h=NULL;

printf("请输入10个以上学生的信息,包括学号,姓名和成绩,以输入“0”为结束符号\n");
scanf("%d %f",&x,&z);
while(x!=0) //循环体,输入各个学生的信息以建立链表
{
s=(struct Student *)malloc(LEN);
s->num=x;
s->name=y;
s->score=z;
s->link=h;
h=s;
scanf("%d %s %f",&x,y,&z);
}
return h;
}

int main() //主函数
{char option1;
struct Student *creat(); //函数声明——建立链表
void print(struct Student *h); //函数声明——输出信息

printf("请输入数字1-5选择相应的程序:\n1-输入信息,建立链表\n2-输出学生信息\n3-增加2名学生的信息\n4-删除不及格学生\n5-查询\n6-按成绩升序打印\n");
option1=getchar();
printf("\n");
switch(option1)
{
case '1':
struct Student *creat();
break;
}
return 0;
}

void print (struct Student *h) //输出信息函数
{
struct Student *p; //在函数中定义struct Student类型变量p
printf("输出之前输入的信息\n");
p=h; //使p指向第一个结点
if(h!=NULL) //若不是空表
do
{printf("%d %s %f",p->num,p->name,p->score);
p=p->link; //使p指向下一个结点
}while(p!=NULL);
}

题目是
建立10人以上学生的链表,信息有学号,姓名,成绩,并完成以下操作
1.输出
2.增加2名学生

我只做了一部分 帮我看看我做的这部分就好了
程序不能运行啊 就是运行时输入1然后系统没反应啊
恳求大神帮助啊 急死我了都

第1个回答  2013-03-26
我勒个去。。很多错误,现在没错误了,你还是认真一句句对一下,你错哪里了吧
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student //定义一个结构体变量struct Student
{int num;
char name[20];
float score;
struct Student *link;
};

struct Student *creat() //建立链表的函数
{
struct Student *h,*s,*p;
int x;
char y[20];
float z;
h=NULL;

printf("请输入10个以上学生的信息,包括学号,姓名和成绩,以输入0为结束符号\n");
scanf("%d%s%f",&x,y,&z);
while(x!=0) //循环体,输入各个学生的信息以建立链表
{
s=(struct Student *)malloc(LEN);
s->num=x;
strcpy(s->name,y);
s->score=z;
if(h==NULL) {p=h=s;}
else
{
p->link=s;
p=s;
}
scanf("%d %s %f",&x,y,&z);
}
p->link=NULL;
return h;
}

int main() //主函数
{char option1;
struct Student* head;
struct Student *creat(); //函数声明--建立链表
void print(struct Student *h); //函数声明--输出信息

printf("请输入数字1-5选择相应的程序:\n1-输入信息,建立链表\n2-输出学生信息\n3-增加2名学生的信息\n4-删除不及格学生\n5-查询\n6-按成绩升序打印\n");
option1=getchar();
printf("\n");
switch(option1)
{
case '1':
head=creat();
print(head);
break;
}
return 0;
}

void print (struct Student *h) //输出信息函数
{
struct Student *p; //在函数中定义struct Student类型变量p
printf("输出之前输入的信息\n");
p=h; //使p指向第一个结点
if(h!=NULL) //若不是空表
do
{printf("%d %s %f\n",p->num,p->name,p->score);
p=p->link; //使p指向下一个结点
}while(p!=NULL);
}本回答被提问者采纳
相似回答
大家正在搜