[Error] 'head' was not declared in this scope 为啥是这个错误啊

我真的是曾哥 2019-03-20 09:08:05
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#define LEN sizeof(Node)
typedef struct _node
{
int value;
struct _node*next;
}Node;

typedef struct _list
{
Node* head;
}List;
void add(Node* head,int number);
int main(int agrc,char const *agrv[])
{
List list;
int number;
list.head=NULL;
head=(List *)malloc(sizeof(List));
do
{
scanf("%d",&number);
if(number!=-1)
{
head=add(&list,number); 《————错误在这,而且有两个 还有一个是[Error] cannot convert 'List* {aka _list*}' to
'Node* {aka _node*}' for argument '1' to 'void add(Node*, int)'
}
}while(number!=-1);
Node *p;
for(p=list.head;p;p=p->next)
{
printf("%d\t",p->value);
}
return 0;
}
void add(List* pList,int number)
{
Node *p=(Node*)malloc(sizeof(Node));
p->value=number;
p->next=NULL;
Node *last=pList->head;
if(last)
{
while(last->next)
{
last=last->next;
}
last->next=p;
}
else
{
pList->head=p;
}
}
...全文
1429 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
我真的是曾哥 2019-03-23
  • 打赏
  • 举报
回复
非常感谢,差不多解决了
拥抱Linux 2019-03-20
  • 打赏
  • 举报
回复

(1)add()函数的声明与底下的原形不一致,具体是第一个参数的类型不一致。
(2)head在main()函数中没有定义过。
(3)add()函数是没有返回值的,如何能赋值呢?

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧