为什么我总是显示 [Warning] assignment from incompatible pointer type [enabled by default]呢代码如下:#include#includestruct student{\x05char name[20];\x05float score;\x05struct student *next;};struct student *create(int n){\x05int i;\x0

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/27 07:06:04
为什么我总是显示[Warning]assignmentfromincompatiblepointertype[enabledbydefault]呢代码如下:#include#includestruct

为什么我总是显示 [Warning] assignment from incompatible pointer type [enabled by default]呢代码如下:#include#includestruct student{\x05char name[20];\x05float score;\x05struct student *next;};struct student *create(int n){\x05int i;\x0
为什么我总是显示 [Warning] assignment from incompatible pointer type [enabled by default]呢
代码如下:
#include
#include
struct student
{
\x05char name[20];
\x05float score;
\x05struct student *next;
};
struct student *create(int n)
{
\x05int i;
\x05struct student *pnew,*head,*ptail;
\x05pnew=(struct shtdent *)malloc(sizeof(struct student));
\x05\x05\x05scanf("%s%f",&pnew->name,&pnew->score);
\x05head=ptail=pnew;
\x05for(i=1;iname,&pnew->score);
\x05\x05(*ptail).next=pnew;
\x05\x05ptail=pnew;
\x05}
\x05(*pnew).next=NULL;
\x05return head;
}

为什么我总是显示 [Warning] assignment from incompatible pointer type [enabled by default]呢代码如下:#include#includestruct student{\x05char name[20];\x05float score;\x05struct student *next;};struct student *create(int n){\x05int i;\x0
两个申请空间的都写成(struct shtdent *)了,难道完整程序中还有struct shtdent的结构体定义?
应该都是pnew=(struct student *)malloc(sizeof(struct student));
修改后经试验没有警告,且能创建成功.
另外,(*ptail).next也可写成ptail->next