|
|
发表于 2012-5-21 11:02:04
|
显示全部楼层
兄弟。。。错误太多了,给你贴个修改过的代码,你自己看吧!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct test
{
int data;
struct test *next;
}wm;
wm *head = NULL;
int main()
{
void Print_wm(wm *h);
wm * Increate_wm(wm *h);
wm * head = NULL;
head = Increate_wm(head);
Print_wm(head);
system("pause");
return 0;
}
void Print_wm(wm *h)
{
wm *p = h;
while(p != NULL)
{
printf("->%d\n",p->data);
p = p->next;
}
printf("->End\n");
}
//添加数据
wm * Increate_wm(wm *h)
{
wm *next = h;
int x ;
while(1)
{
printf("输入数据:\n");
scanf("%d",&x);
if(x == 0)
{
break;
}
if(h == NULL)
{
h = (wm *)malloc(sizeof(wm));
next = h;
h->data = x;
h->next = NULL;
}
else
{
next->next = (wm *)malloc(sizeof(wm));
next = next->next;
next->data = x;
next->next = NULL;
}
}
return h;
}
|
|