首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

看看这个程序哪里出错了?解决方法

2012-05-10 
看看这个程序哪里出错了?#include stdlib.h#include stdio.hstruct list{int datastruct list *next

看看这个程序哪里出错了?
#include "stdlib.h"
#include "stdio.h"

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));
  ptr=head;
  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;
  }
}

[解决办法]
ptr=head;这句是什么意思呢?head是一个未初始化的数据,你怎么就用呢?如果你想把ptr的值赋值给head的话,那应该是这样的:head=ptr
[解决办法]
对 写反了。

探讨

ptr=head;这句是什么意思呢?head是一个未初始化的数据,你怎么就用呢?如果你想把ptr的值赋值给head的话,那应该是这样的:head=ptr

热点排行