很短的一个简单链表,帮忙看看

来源:百度知道 编辑:UC知道 时间:2024/06/06 19:43:10
如何输入 ???? 就感觉自己很乱

#include<stdio.h>
#include<stdlib.h>

struct node
{
char name[20];
int num;
struct node *next;
}*head,*p,*nod;

void main()
{
int i,j;
head = (struct node *)malloc(sizeof(struct node));
p=(struct node *)malloc(sizeof(struct node)); //这里每次有创建吗 ???
p=head->next;
printf("Input the number ");
printf("Input the name");
gets(p->name); //这里开始有问题了
getchar();
printf("Input the num");
scanf("%d",&p->num);

printf("%s %d",p->name,p->num);

}

希望各位看看

#include<stdio.h>
#include<stdlib.h>

struct node
{
char name[20];
int num;
struct node *next;
}*head,*p,*nod;

void main()
{
int i,j;
head = (struct node *)malloc(sizeof(struct node));
p = (struct node *)malloc(sizeof(struct node)); //这里每次有创建吗 ???

head->next = p; //原来为 p=head->next;

printf("Input the num "); //输入数字

scanf("%d", &p->num);

printf("Input the name ");
scanf("%s", p->name);

printf("%s %d ", p->name, p->num);

getchar();//这句是为了方便看结果,可以不要

}