为什么无法打印输出啊!!!

来源:百度知道 编辑:UC知道 时间:2024/06/08 05:52:18
以下是关于一个链表的问题,能够输入,但打印老师出错~~~请各位帮个忙,谢谢了!!
#include<stdio.h>
#include<stdlib.h>
#define M sizeof(struct node)
struct node
{
char name;
int data;
struct node *next;
};
void scanlist(struct node *p)
{
struct node *m,*t;
int x;
m=p;
printf("1-添加\n2-退出\n请输入:");
scanf("%d",&x);
while(x!=2)
{
t=(struct node*)malloc(M);
printf("name:");
scanf("%s",&t->name);
printf("data:");
scanf("%d",&t->data);
m->next=t;
m=t;
t->next=NULL;
printf("1-添加\n2-退出\n请输入:");
scanf("%d",&x);
}
}
void printlist(struct node *p)
{
struct node *m;
m=p;
m=m->next;
while(m!=NULL)
{
printf("name:%s data:%d\n",m->name,m->data);
m=m->next;

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

#define M sizeof(struct node)
#define N 10 //定义宏

struct node
{
char name[N]; //定义一个数组 按你的形式才能输出
int data;
struct node *next;
};

void scanlist(struct node *p)
{
struct node *m,*t;
int x;
m=p;
printf("1-添加\n2-退出\n请输入:");
scanf("%d",&x);
while(x!=2)
{
t=(struct node*)malloc(M);
printf("name:");
scanf("%s",t->name);
printf("data:");
scanf("%d",&t->data);
m->next=t;
m=t;
t->next=NULL;
printf("1-添加\n2-退出\n请输入:");
scanf("%d",&x);
}
}

void printlist(struct node *p)
{
struct node *m;
m=p;
m=m->next;
while(m->next!=NULL)
{
printf("name:%s data:%d\n",m->name,m->data)