回复 3楼 lp617
这个程序错在那!!!编译没问题但是运行不对
#include<stdio.h>
#include<stdlib.h>
typedef struct student{
int id;
char name[10];
struct student *next;
}student,*st;
//声明
void set(st ps);
void show(st ps);
st findtail(st ps);
void output(st stu_1,st stu);
//主函数
int main(){
st stu=calloc(100,sizeof(student));
st stu_1=NULL;
//添加第一个数据
st stu_2=calloc(1,sizeof(student));
set(stu_2);
st pt=findtail(stu_2);
if(pt==NULL){
stu_1=stu_2;
}else{
pt=stu_2;
}
//show(stu_2);
stu=stu_2;
//添加第二个数据
stu_2=calloc(1,sizeof(student));
set(stu_2);
pt=findtail(stu_2);
if(pt==NULL){
stu_1=stu_2;
}else{
pt=stu_2;
}
stu=stu_2;
//show(stu_2);
//添加第三个数据
stu_2=calloc(1,sizeof(student));
set(stu_2);
pt=findtail(stu_2);
if(pt==NULL){
stu_1=stu_2;
}else{
pt=stu_2;
}
stu=stu_2;
stu_1=stu;
output(stu_1,stu);
return 0;
}
void output(st stu_1,st stu){
while(1){
if(stu==NULL){
printf("11111111111111111");
break;
}
else{
show(stu);
stu=stu->next;
}
}
}
//输入
void set(st ps){
scanf("%d\t%s",&(ps+0)->id,(ps+0)->name);
ps->next=NULL;
}
//显示
void show(st ps){
int index=0;
for(index=0;index<3;index++){
printf("%d\t%s\n",(ps+index)->id,(ps+index)->name);
}
}
st findtail(st ps){
if(ps==NULL){
return ps;
}
while(1){
if(ps->next==NULL){
return ps->next;
}
ps=ps->next;
}
}