C语言关于链表的问题 在线等!!!

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:28:40
#include "stdio.h"
#include <conio.h>
#define DATATYPE1 int
typedef struct node
{DATATYPE1 data;
struct node *next;
}LINKLIST;

main()
{
LINKLIST *head, *last, *t, *q;
int m;
clrscr();
printf("Please input a number.");
t=malloc(sizeof(LINKLIST));
head=t; last=t;
t->next=NULL;
while((m=scanf("%d"))!=0)
{
t=malloc(sizeof(LINKLIST));
t->data=m;
last->next=t;
last=t;
t->next=NULL;
printf("%d\t",t->data);
}
}
不知道为什么m的值一直为0
好像是while((m=scanf("%d"))!=0)这一行的问题
应该怎么改
当输入0时不跳出循环是为什么啊
我需要每次都输入一个值啊

while(scanf("%d", &m)!=0)

你是想写成这样吧?注意scanf的用法

scanf函数返回值是读取了几个变量的值(比如此读取了1个数,则返回1),并不是所读取的变量的值,建议将程序改成这样
------------------------

scanf("%d", &m);
while((m != 0)
{

t=malloc(sizeof(LINKLIST));
t->data=m;
last->next=t;
last=t;
t->next=NULL;
printf("%d\t",t->data);

scanf("%d", &m);

}

scanf("%d",&m);
while(m!=0)

错误很多!