运行结果无法操作 新手入门 程序检错

来源:百度知道 编辑:UC知道 时间:2024/05/16 18:19:05
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct list
{
char name[20];
char num[12];
char telephone[12];
int score;
struct list *next;
}list,*lnode;
list listl;
int size;
size=sizeof(list);
lnode init()
{
lnode L=(lnode)malloc(sizeof(size));
L->next=NULL;
return L;
}
lnode insert(lnode L)
{
int k;
lnode p,q;
p=(lnode)malloc(size);
p->next=NULL;
printf("请输入姓名");
scanf("%s",p->name);
printf("请输入学号");
scanf("%s",p->num);
printf("请输入电话");
scanf("%s",p->telephone);
printf("请输入学分");
scanf("%d",p->score);
for(q=L;!q;q=q->next);
L=q;
L->next=p;
p=L->next;

错误太多了 逻辑错都改了
不能保证运行结果是对的
我只能说用结点判断是否为空作为条件语句进行循环或if操作是会出问题的
当下一结点没有定义的时候不代表就为空.

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct list
{
char name[20];
char num[12];
char telephone[12];
int score;
struct list *next;
}list,*lnode;
list listl;
//int size;
//size = sizeof(list);
lnode init()
{
lnode L=(lnode)malloc(sizeof(list));
L->next=NULL;
return L;
}
lnode insert(lnode L)
{
lnode p,q;
p=(lnode)malloc(sizeof(list));
p->next=NULL;
printf("请输入姓名");
scanf("%s",p->name);
printf("请输入学号");
scanf("%s",p->num);
printf("请输入电话");
scanf("%s",p->telephone);
printf("请输入学分");
scanf("%d",p->score);
for(q=L;!q;q=q->next);