为什么我总是显示 [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/08/27 11:56:48
![为什么我总是显示 [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](/uploads/image/z/6928092-36-2.jpg?t=%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E6%80%BB%E6%98%AF%E6%98%BE%E7%A4%BA+%5BWarning%5D+assignment+from+incompatible+pointer+type+%5Benabled+by+default%5D%E5%91%A2%E4%BB%A3%E7%A0%81%E5%A6%82%E4%B8%8B%EF%BC%9A%23include%23includestruct+student%7B%5Cx05char+name%5B20%5D%3B%5Cx05float+score%3B%5Cx05struct+student+%2Anext%3B%7D%3Bstruct+student+%2Acreate%28int+n%29%7B%5Cx05int+i%3B%5Cx0)
为什么我总是显示 [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