关于指针赋值的问题
#include "stdafx.h"#include "stdlib.h"
int n=0;
struct student
{
int num;
float scores;
struct student *next;
};
struct student * construct()//创建链表
{
struct student *head,*p1,*p2;
p1=(struct student *)malloc(sizeof(struct student *));
p2=p1;
head=p1;
scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
while(1)
{
p1=(struct student *)malloc(sizeof(struct student *));
scanf_s("%d%f",&(p1->num) ,&(p1->scores) );
if(p1->num ==0)
{
p2->next=NULL;
break;
}
else
{
p2->next =p1;
p2=p1;
n=n+1;
}
}
return head;
}
void print(struct student * stu)//输出链表
{ struct student * st;
st=stu;
do
{
printf("%d %f\n",st->num ,st->scores );
st=st->next ;
}while(st!=NULL);
}
int _tmain(int argc, _TCHAR* argv[])
{
struct stuent *p;
p=construct();//这里不能赋值错误 1 error C2440: “=”: 无法从“student *”转换为“wmain::stuent *”
print(p);//这里的参数也不对
return 0;
}