求各位大虾帮我看看这个程序哪里错了~~~~先谢了

来源:百度知道 编辑:UC知道 时间:2024/06/30 23:46:34
struct lesson{
char lesname;
float score[3];/*[1]final[2]normal[3]exam*/
char credit;
char pass;
};

struct student {
long number;
char name[15];
char sex;
int classes;
int dormitory;
struct lesson lesson[N];
struct student *next;
};

struct student *luru(){

char cho;
b++;
struct student *p1,*p2;
num=0;
p1=p2=(struct student*)malloc(LEN);
infscanf(p1);

printf("continue to input student data?Y/N\n");
scanf("%s",&cho);
head=NULL;
while(cho=='Y'||cho=='y'){
num++;
if(num==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
infscanf(p1);
printf("continue to input student data?Y/N");
scanf("%s",&cho);
} p2->next=NULL;
return(p2);
}

inscanf()一些数据进行录入

你是不是用VS在编C程序?所以有scanf("%s",&cho);的问题?这个问题我也遇到过,换成cho=getchar();试一试。

不管luru往哪里添加新节点,只要head是全局变量luru就不需要返回值,因为要添加的链表只有一个而已。就像这样:

void luru(){
char cho;
struct student *p;
do{
if(head==0){
head=(struct student *)malloc(sizeof(struct student));
head->next=0;
inscanf(head);
}
else{
p=head;
while(p->next!=0){
p=p->next;
}
p->next=(struct student *)malloc(sizeof(struct student));
p=p->next;
p->next=0;
inscanf(p);
}
printf("continue to input student data?Y/N");
cho=getchar();
}while(cho=='Y'||cho=='y');
}

很多变量都没有事先声明

你是不是把全局变量和main函数里的局部变量搞混了