请教前辈一个C语言链表的问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 11:29:37
请教前辈,为什么在提示完“please input the record which you want to insert:”接收数据的时候当我刚输入完age的值的时候一敲回车就自动退出了,我还有一个数组mark[3]没赋值呢。
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define LEN sizeof(struct student)

struct student
{
char name[30];
long number;
char gender;
int age;
float mark[3];
struct student *next;
};

int record = 0;

struct student *listinsert(struct student *head);

int main(void)
{
struct student *head;
head = initlist();
head = listinsert(head);
getch();
return 0;
}

struct student *initlist(void)
{
struct student *head;
head = NULL;
return head;
}

struct student *listinsert(struct student *head)
{
struct student *p1, *p2, *pi;
p1 = p2 = head;
printf("please input the record whi

字符串输入时,变量前面不用加&
就是 scanf("%s %ld %c %d",&pi->name,&pi->number,&pi->gender,&pi->age);
要改成
scanf("%s %ld %c %d",pi->name,&pi->number,&pi->gender,&pi->age);

scanf("%s %ld %c %d",&pi->name,&pi->number,&pi->gender,&pi->age);
你要采用跟这句格式相同的间隔符并且注意接收数据的字节个数,当输入“gender”这一项时只输入一个字符就可以了
比方说“erfef 3 e 33”就不会结束
她退出是因为你输入的格式不对

注意,你全部的输入,是以空格隔开的,
所以你输入时形式是这样 1 2 3 . . .(回车) 输入成绩时也是这样形式,

你输入格式不是这样,就可能出错

你要使用跟这句格式相同的间隔符并且当然应注意接收数据的字节个数,例如:scanf("%s %ld %c %d",&pi->name,&pi->number,&pi->gender,&pi->age),当输入“gender”这一项时只输入一个字符就可以了.
牢记:敲回车是在输入完毕后进行!