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

为什么出错了?什么原因?该如何解决

2012-02-07 
为什么出错了?什么原因??#include stdio.h#include malloc.h#include string.hstructstu{intnumcha

为什么出错了?什么原因??
#include <stdio.h>
#include <malloc.h>
#include <string.h>
struct   stu{
int   num;
char   name[20];
char   sex;
float   score;
}student[2]={{050101, "许元元 ", 'w ',502},{050102, "张帆 ", 'm ',498}};

typedef   struct   node{
struct   stu   data;
struct   node   *next;
}Llist,*linklist;

createList(linklist   p,struct   stu   student[],int   n)
{linklist   h=NULL;
  int   i;Llist   *s,*r;
for(i=0;i <n;i++)
{s=(Llist   *)malloc(sizeof(Llist));
s-> data.num=student[i].num;
strcpy(s-> data.name,student[i].name);
s-> data.sex=student[i].sex;
s-> data.score=student[i].score;
s-> next=NULL;
if(h==NULL){h=s;r=s;}
else{r-> next=s;
r=s;}
}
}
main()
{Llist   *a1=NULL,*p;
createList(&a1,student,2);
  p=a1;
  while(p)
  {printf( "\n%d\t%s\t%c\t%f ",p-> data.num,p-> data.name,p-> data.sex,p-> data.score);
  p=p-> next;    
  }

}

[解决办法]
createList(a1,student,2);
p=a1;
参数类型不对,改成上面的试试
[解决办法]
1, createList()前面应该加个void

2, 你函数的原型是: void createList(linklist,struct stu *,int)

你调用时:createList(&a1,student,2);
变成了:void createList(linklist *,struct stu *,int)

本身已经是指针了, 再取地址干吗?

热点排行