C语言 很简单的链表编译器不给过 找不出问题

来源:百度知道 编辑:UC知道 时间:2024/05/28 11:26:00
#include <stdio.h>
#include <malloc.h>
#define Len sizeof(a)
#define null 0
#include <conio.h>

struct a* gethead()//建立

{
struct a
{
int k;
struct a *next;
};
struct a *head, *p2;
printf("please enter data.");
head=p2=(struct a*)malloc(Len);
scanf("%d",p2->k);
while(p2->k!=0)
{
p2->next=(struct a*)malloc(Len);
p2=p2->next;
scanf("%d",p2->k);
}
p2->next=null;

return "head";

}
main()
{
struct a *gethead();
}
错误信息:

In function `a* gethead()':

cannot convert `const char*' to `a*' in return
head本来就是结构体指针啊

return "head"; 为什么函数返回是字符串,你的返回类型是结构体指针的
cannot convert `const char*' to `a*' in return
不能反转char * 到 a* 的返回值

#include <stdio.h>
#include <malloc.h>
#define Len sizeof(a)
#define null 0
#include <conio.h>
struct a
{
int k;
struct a *next;
};

struct a* gethead()//建立

{

struct a *head, *p2;
printf("please enter data.");
head=p2=(struct a*)malloc(Len);
scanf("%d",&p2->k); //输入要地址
while(p2->k!=0)
{
p2->next=(struct a*)malloc(Len);
p2=p2->next;
scanf("%d",&p2->k); //输入要地址
}
p2->next=null;

return head; //返回指针

}
main()
{
struct a * head=gethead(); //变量名都没有
}

return "head",为什么要加双引号,