C语言 error LNK2001: unresolved external symbol 问题:编译没问题 ,但是运行不了,怎么解决? 5
#include<stdio.h>#include<ctype.h>#include<stdlib.h>#defineNODEstructnode#defineSTACK...
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define NODE struct node
#define STACK struct stack
#define N 5
#define M 1000
#define NUMBEER 0
#define SYMBOL 1
NODE
{
short num;
NODE *sub[N];
};
STACK
{
NODE *node;
STACK *next;
};
STACK *Stack=NULL;
extern char String[M]; /* 输入字符串 */
extern short Ptr; /* 字符数组指针 */
extern NODE *Root;
void error(char *string)
{
printf("%s\n", string);
exit(0);
}
void input(void)
{
int i=-1, c;
while( (c=getchar()) != EOF )
if(!isspace(c)) /* 是空字符? */
String[++i] = c; /* 将空字符滤去 */
String[++i] = '\0';
printf("Input string is: [%s]\n", String);
}
void push(NODE *node)
{
STACK *s;
s = (STACK *)(malloc(sizeof(STACK)));
if(s == NULL)
error("no space for stack!");
s->node = node;
s->next = Stack;
Stack = s;
}
NODE *pop(void)
{
NODE *node;
STACK *s;
if(Stack == NULL)
return(NULL);
node = Stack->node;
s = Stack;
Stack = s->next;
free(s);
return(node);
}
short GetData(short *key)
{
char c;
*key = 0;
if(!isdigit(c = String[Ptr]))
return(0); /* 失败 */
/* 从String中取一个结点值 */
while(isdigit(c))
{
*key = *key * 10 + String[Ptr] - '0';
c = String[++Ptr];
}
if(c == ',' || c == '(' || c == ')')
return(1); /* 成功 */
return(0); /* 失败 */
}
short GetSymbol(char symbol)
{
/* 从String中取一个符号 */
if(String[Ptr++] == symbol)
return(1); /* 成功 */
Ptr--;
return(0); /* 失败 */
}
void MakeNode(void)
{
short num, j;
short k=0;
NODE *node;
/* 1. 取左括号*/
if(!GetSymbol('('))
return; /* 取不到(空树),返回 */
/* 2. 取子结点 */
while(GetData(&num))
{
node = (NODE *)(malloc(sizeof(NODE)));
if(node == NULL)
error("no space!");
for(j=0; j<N; j++)
node->sub[j] = NULL;
node->num = num;
Stack->node->sub[k] = node;
push(node);
MakeNode();
if(GetSymbol(',')) /* 3. 取逗号 */
{
k++;
pop();
}
else if(GetSymbol(')')) /* 4. 取右括号*/
pop();
else
error("format error!");
}
}
void MakeTree()
{
short num, j;
if(GetData(&num)) /* 获取根结点值*/
{
Root = (NODE *)(malloc(sizeof(NODE)));
if(Root == NULL)
error("no space for Root!");
for(j=0; j<N; j++)
Root->sub[j] = NULL;
Root->num = num;
push(Root);
MakeNode();
}
else
error("Empty tree!");
} 展开
#include <ctype.h>
#include <stdlib.h>
#define NODE struct node
#define STACK struct stack
#define N 5
#define M 1000
#define NUMBEER 0
#define SYMBOL 1
NODE
{
short num;
NODE *sub[N];
};
STACK
{
NODE *node;
STACK *next;
};
STACK *Stack=NULL;
extern char String[M]; /* 输入字符串 */
extern short Ptr; /* 字符数组指针 */
extern NODE *Root;
void error(char *string)
{
printf("%s\n", string);
exit(0);
}
void input(void)
{
int i=-1, c;
while( (c=getchar()) != EOF )
if(!isspace(c)) /* 是空字符? */
String[++i] = c; /* 将空字符滤去 */
String[++i] = '\0';
printf("Input string is: [%s]\n", String);
}
void push(NODE *node)
{
STACK *s;
s = (STACK *)(malloc(sizeof(STACK)));
if(s == NULL)
error("no space for stack!");
s->node = node;
s->next = Stack;
Stack = s;
}
NODE *pop(void)
{
NODE *node;
STACK *s;
if(Stack == NULL)
return(NULL);
node = Stack->node;
s = Stack;
Stack = s->next;
free(s);
return(node);
}
short GetData(short *key)
{
char c;
*key = 0;
if(!isdigit(c = String[Ptr]))
return(0); /* 失败 */
/* 从String中取一个结点值 */
while(isdigit(c))
{
*key = *key * 10 + String[Ptr] - '0';
c = String[++Ptr];
}
if(c == ',' || c == '(' || c == ')')
return(1); /* 成功 */
return(0); /* 失败 */
}
short GetSymbol(char symbol)
{
/* 从String中取一个符号 */
if(String[Ptr++] == symbol)
return(1); /* 成功 */
Ptr--;
return(0); /* 失败 */
}
void MakeNode(void)
{
short num, j;
short k=0;
NODE *node;
/* 1. 取左括号*/
if(!GetSymbol('('))
return; /* 取不到(空树),返回 */
/* 2. 取子结点 */
while(GetData(&num))
{
node = (NODE *)(malloc(sizeof(NODE)));
if(node == NULL)
error("no space!");
for(j=0; j<N; j++)
node->sub[j] = NULL;
node->num = num;
Stack->node->sub[k] = node;
push(node);
MakeNode();
if(GetSymbol(',')) /* 3. 取逗号 */
{
k++;
pop();
}
else if(GetSymbol(')')) /* 4. 取右括号*/
pop();
else
error("format error!");
}
}
void MakeTree()
{
short num, j;
if(GetData(&num)) /* 获取根结点值*/
{
Root = (NODE *)(malloc(sizeof(NODE)));
if(Root == NULL)
error("no space for Root!");
for(j=0; j<N; j++)
Root->sub[j] = NULL;
Root->num = num;
push(Root);
MakeNode();
}
else
error("Empty tree!");
} 展开
展开全部
编译不会有问题的,问题出现在连接的时候 你的变量有extern 声明的 但是它没有真正的实体,你只告诉了编译你有这么一个变量在外部定义的,但是它压根没找到它的实体
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
明显都 error 了 怎么能没问题??楼上正解。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询