errror C 2061 语法错误:标识符‘’Nodeptr‘’

TIAWE 2018-09-20 09:32:53
#include <stdio.h>
#include <stdlib.h>
int FindPrevious(int nun, NodePtr header);

struct ListNode {
int num;
struct ListNode *next;
};
typedef struct ListNode Node;
typedef Node *NodePtr;

int main() {
int n, i,a;
struct ListNode *head, *p;
printf("Please enter the number of data you want to input:");
scanf_s("%d", &n);
head = (struct ListNode*)malloc(sizeof(struct ListNode)); //Create the header node
p = (struct ListNode*)malloc(sizeof(struct ListNode)); //Create the first node
p = head->next;
printf("Please enter numbers you want to input:\n");
for (i = 0; i < n; i++) {
scanf_s("%d", &p->num);
p->next = (struct ListNode*)malloc(sizeof(struct ListNode));
p = p->next;
}
p = head->next;
NodePtr xNode=head;
printf("Please input the node value :\n");
scanf_s("%d", &a);
FindPrevious(a, xNode);
getchar();
}

int FindPrevious(int number, NodePtr header) {
NodePtr p;
p = header;
while (p->next&&p->next->num != number) {
p = p->next;
}
if (p->next) {
printf("The previous Node of %d is %d\n", number, p->num);
}
else {
printf("There is no data there!\n");
}

}
...全文
435 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
@风轻云淡_ 2018-09-21
  • 打赏
  • 举报
回复
如楼上所说,遵循先定义后使用,编译器默认是从上往下搜寻的,所以必须要把声明或者实现放在使用的前面。
AlbertS 2018-09-21
  • 打赏
  • 举报
回复
int FindPrevious(int nun, NodePtr header);

这一行移到NodePtr 定义之后
zangfong 2018-09-20
  • 打赏
  • 举报
回复
你得把函数FindPrevious的声明放到结构体的定义之后。不然NodePtr都还未定义,编译器不认识

#include <stdio.h>
#include <stdlib.h>


struct ListNode
{
int num;
struct ListNode *next;
};
typedef struct ListNode Node;
typedef Node *NodePtr;

int FindPrevious(int nun, NodePtr header);

int main()
{
//...
}
TIAWE 2018-09-20
  • 打赏
  • 举报
回复

69,382

社区成员

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

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