满意答案
The369end
2013.02.06
采纳率:41% 等级:12
已帮助:6173人
#include
#include
struct list
{
int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
void main()
{
link ptr,head;
int num,i;
ptr=(link)malloc(sizeof(node));
head=ptr; //这里搞反了
printf("please input 5 numbers==>\n");
for(i=0;i<=4;i++)
{
scanf("%d",&num);
ptr->data=num; //应该加上这一句
ptr->next=(link)malloc(sizeof(node));
if(i==4)ptr->next=NULL;
else ptr=ptr->next;
}
ptr=head;
while(ptr!=NULL)
{
printf("The value is ==>%d\n",ptr->data); //加换行符好看些
ptr=ptr->next;
}
}
00分享举报