C语言新人 求大神
细水丿 2014-03-16 12:13:25 #include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define LISTSIZE 10
typedef struct LinkNode{
int data;
struct LinkNode *next;
}LN;
LN *InitList()
{
LN *List, *p;
int n=0;
List=(LN *)malloc(sizeof(LN));
if(!List) { printf("ERROR!\n"); exit(0);}
List->next=NULL;
while(n<LISTSIZE){
p=(LN *)malloc(sizeof(LN));
p->next=List->next;
List->next=p;
n++;
}
return List;
}
void IOputData(LN *List)
{
char ch;
LN *p=NULL;
int n=0;
p=List->next;
printf("input data:");
while(p){
scanf("%d", &p->data);
p=p->next;
n++;
}
printf("please press any key to continue~\n");
ch=getch();
p=List->next;
while(p){
printf("%d", p->data);
p=p->next;
}
}
main()
{
LN *List=NULL;
List=InitList();
IOputData(&List);
}
运行以后,在输入数据界面,只输入一个数就弹出错误窗口了。求解!!