error C2065 未声明的标识符。 已经引入头文件为什么还是未声明?

qq_34378352 2016-10-11 11:16:57
#include "LinkedStack.h"

#define status int
#define pane_height 51
#define pane_width 51

int maze[pane_width][pane_height]={0};

void AddwallList(Node *head, int x, int y){
if(x>1){
if(maze[x-2,y]!=0){
Push(head, x-1, y);
}
}
if(x<pane_width-2){
if(maze[x+2,y]!=0){
Push(head, x+1, y);
}
}
if(y>1){
if(maze[x,y-2]!=0){
Push(head, x, y-1);
}
}
if(y<pane_width-2){
if(maze[x,y+2]!=0){
Push(head, x, y+1);
}
}
}

status theMaze(){
int a,b,c;//use for init

//init the maze
for (a=0,b=0,c=pane_width-1;a<pane_height;){
maze[a][b]=2;
maze[a][c]=2;
a++;
}
for (a=0,b=0,c=pane_height-1;b<pane_width;){
maze[a][b]=2;
maze[c][b]=2;
b++;
}

//all is wall
for (a=1;a<pane_height-1;){
for(b=2;b<pane_width-1;){
maze[a][b]=1;
b+=1;
}
a+=1;
for(b=1;b<pane_width-1;){
maze[a][b]=1;
b+=1;
}
a+=1;
}

//init the wallList

Node *head; (错误 6 error C2065: “head”: 未声明的标识符 )
head = creat(); (错误 2 error C2275: “Node”: 将此类型用作表达式非法)

//pick a cell as a part of amze, adding walls of the cell to wallList
maze[1][1]=0;
AddwallList(head, 1, 1);

//printf the maze
for (a=0;a<pane_height;){
for(b=0;b<pane_width;){
printf("%d",maze[a][b]);
b++;
}
a++;
printf("\n");
}
return 1;
}

int main(){
theMaze();
system("pause");
}

用vs2010 和C语言写的。有点不明白为什么已经引用头文件还是不能定义
...全文
1845 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sniper_Pan 2016-10-12
  • 打赏
  • 举报
回复
VS2013测试通过,建议完全重编下试试
qq_34378352 2016-10-12
  • 打赏
  • 举报
回复
谢谢指正!Bug我都修改了。但是还是老情况 Node *head; head = creat(); 会提示head未声明的标识符,Node此类型用作表达式非法。 是VS2010的问题吗? 修正以后的代码: #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct vector{ int x; int y; }vec; typedef struct node{ vec a; struct node *next; }Node; Node *creat(); void DestoryStack(Node *head); int StackEmpty(Node *head); int StackLenth(Node *head); int GetTop(Node *head, vec *b); void Push(Node *head, int a, int b); void Pop(Node *head); Node *creat(){ Node *head = NULL; head = (Node *)malloc(sizeof(Node)); if (head == NULL){ printf("fail to creat"); return NULL; } head -> next = NULL; return head; } void DestoryStack(Node *head){ if (head){ Node *tail, *pnew = NULL; if (head ->next) tail = head ->next; free(head); while (tail ->next){ pnew = tail ->next; free(tail); } free(pnew); } } int StackEmpty(Node *head){ if(head->next){ return 1; } return 0; } int StackLenth(Node *head){ int num; Node *tail = NULL; if(head)num=1; else return 0; tail = head; if(tail->next){ tail = tail->next; num++; } return num; } int GetTop(Node *head, vec *b){ Node *tail = NULL; tail = head; if(!StackEmpty(head)){ if(head->next){ tail = tail->next; } b= &tail->a; return 1; } return 0; } void Push(Node *head, int a, int b){ Node *tail, *pnew = NULL; tail = head; if(!StackEmpty(head)){ if(head->next){ tail = tail->next; } tail->next=(Node *)malloc(sizeof(Node)); pnew = tail->next; pnew->next = NULL; pnew->a.x = a; pnew->a.y = b; } } void Pop(Node *head){ Node *tail, *last = NULL; tail = head; last = head; if(!StackEmpty(head)){ if(head->next){ tail = last; last = last->next; } free(last); tail->next =NULL; } }
paschen 2016-10-11
  • 打赏
  • 举报
回复
if (head = NULL){ 改成 if (head == NULL){ GetTop 不是所有路径都有返回 extern Node *creat(){ 写成 Node *creat(){ 吧
dustpg 2016-10-11
  • 打赏
  • 举报
回复
我这没问题, 不过bug太多了, 严重性 代码 说明 项目 文件 行 禁止显示状态 警告 C4709 逗号运算符在数组索引表达式内 DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\main.c 11 警告 C4709 逗号运算符在数组索引表达式内 DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\main.c 16 警告 C4709 逗号运算符在数组索引表达式内 DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\main.c 21 警告 C4709 逗号运算符在数组索引表达式内 DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\main.c 26 警告 C4706 条件表达式内的赋值 DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\linkedstack.h 26 错误 C4703 使用了可能未初始化的本地指针变量“tail” DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\linkedstack.h 40 错误 C4703 使用了可能未初始化的本地指针变量“pnew” DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\linkedstack.h 44 警告 C4701 使用了可能未初始化的局部变量“tail” DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\linkedstack.h 40 警告 C4701 使用了可能未初始化的局部变量“pnew” DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\linkedstack.h 44 警告 C4715 “GetTop”: 不是所有的控件路径都返回值 DDT1 c:\users\administrator\documents\visual studio 15\projects\project1\ddt1\linkedstack.h 77
qq_34378352 2016-10-11
  • 打赏
  • 举报
回复
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct vector{ int x; int y; }vec; typedef struct node{ vec a; struct node *next; }Node; extern Node *creat(); void DestoryStack(Node *head); int StackEmpty(Node *head); int StackLenth(Node *head); struct vector GetTop(Node *head); void Push(Node *head, int a, int b); void Pop(Node *head); extern Node *creat(){ Node *head; head = (Node *)malloc(sizeof(Node)); if (head = NULL){ printf("fail to creat"); return NULL; } head -> next = NULL; return head; } void DestoryStack(Node *head){ if (head){ Node *tail, *pnew; if (head ->next) tail = head ->next; free(head); while (tail ->next){ pnew = tail ->next; free(tail); } free(pnew); } } int StackEmpty(Node *head){ if(head->next){ return 1; } return 0; } int StackLenth(Node *head){ int num; Node *tail; if(head)num=1; else return 0; tail = head; if(tail->next){ tail = tail->next; num++; } return num; } struct vector GetTop(Node *head){ Node *tail; tail = head; if(!StackEmpty(head)){ if(head->next){ tail = tail->next; } return tail->a; } } void Push(Node *head, int a, int b){ Node *tail, *pnew; tail = head; if(!StackEmpty(head)){ if(head->next){ tail = tail->next; } tail->next=(Node *)malloc(sizeof(Node)); pnew = tail->next; pnew->next = NULL; pnew->a.x = a; pnew->a.y = b; } } void Pop(Node *head){ Node *tail, *last; tail = head; last = head; if(!StackEmpty(head)){ if(head->next){ tail = last; last = last->next; } free(last); tail->next =NULL; } } 这是头文件。麻烦帮忙看看!!

70,023

社区成员

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

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