c语言使用头文件调用其他文件函数时时链接报错,新手求指教~~
我写了一个栈的基本操作的ds3_seqStack2.cpp文件,函数声明和数据结构定义用了头文件ds3_seqStack2.h,然后写一个test.cpp文件include这个.h文件以调用栈基本函数,但是连接报错,下帖代码,求指教/***********ds3_seqStack2.cpp************/
#include"stdio.h"
#include"stdlib.h"
#include "ds3_seqStack2.h"
int initStack(SqStack &s,int n) {
s.data = (char *)malloc(n);
if(s.data == NULL) {
printf("space alloction fail\n");
exit(0);
}
s.stackSize = n;
s.top = -1;
return 1;
}
int push(SqStack &s,char x) {
if(s.top == s.stackSize-1) {
printf("the stack is full\n");
return 0;
}
s.data[++s.top] = x;
return 1;
}
int pop(SqStack &s,char &x) {
if(stackEmpty(s)) {
printf("the stack is empty\n");
return 0;
}
x = s.data[s.top];
s.top--;
return 1;
}
int stackEmpty(SqStack s) {
if(s.top == -1) {
return 1;
}
return 0;
}
int stackLength(SqStack s) {
return s.top+1;
}
int clearStack(SqStack &s) {
s.top = 1;
return 1;
}
void stackTraverse(SqStack s) {
for(int i=0;i<s.top+1;i++) {
printf("%-3d",s.data[i]);
}
printf("\n");
}
/***********ds3_seqStack2.h************/
#ifndef SEQSTACK2_H
#define SEQSTACK2_H
typedef struct stack {
char* data;
int top;
int stackSize;
}SqStack;
int initStack(SqStack &s,int n);
int push(SqStack &s,char x);
int pop(SqStack &s,char &x);
int stackEmpty(SqStack s);
int clearStack(SqStack &s);
int stackLength(SqStack s);
void stackTraverse(SqStack s);
#endif
/***********test.cpp************/
#include"stdio.h"
#include"ds3_seqStack2.h"
int parenthesesMatch(char* s);
void main() {
char s[20];
printf("Please input a expressions\n");
scanf("%s",s);
if(parenthesesMatch(s)) {
printf("parentheses Match\n");
}else {
printf("parentheses doesn't Match\n");
}
}
int parenthesesMatch(char* str) {
SqStack s;
char x;
initStack(s,10);
while(*str) {
if(*str == '('|| (*str) == '[') {
push(s,*str);
str++;
}
else if(*str == ')') {
if(s.data[s.top] == '(') {
pop(s,x);
str++;
}
else {
return 0;
}
}
else if(*str == ']') {
if(s.data[s.top] == '[') {
pop(s,x);
str++;
}
else {
return 0;
}
}
else {
str++;
}
}
if(stackEmpty(s)) {
return 1;
}else {
return 0;
}
}
error LNK2001: unresolved external symbol "int __cdecl stackEmpty(struct stack)" (?stackEmpty@@YAHUstack@@@Z)
error LNK2001: unresolved external symbol "int __cdecl pop(struct stack &,char &)" (?pop@@YAHAAUstack@@AAD@Z)
error LNK2001: unresolved external symbol "int __cdecl push(struct stack &,char)" (?push@@YAHAAUstack@@D@Z)
error LNK2001: unresolved external symbol "int __cdecl initStack(struct stack &,int)" (?initStack@@YAHAAUstack@@H@Z)
fatal error LNK1120: 4 unresolved externals