高手请帮我解决下关于redeclaration的问题

ljy228 2007-05-16 08:10:15
我的文件包含CALCUL.h CALCUL.c CALCUL.prj
其中里面引用了STACK里面的STACK.C,STACK.H程序
在CALCUL运行的时候总是出现错误提示 redeclaration of Element
redeclaration of Next
而那两个重定义的变量正好是STACK里面的变量
请高手帮我看看是什么问题。。。
下面是头文件:
/*CALCUL.C*/
#include<stdio.h>
#include".\code\stack\STACK.c"
#include".\code\caculate\CALCUL.h"

/*CALCUL*/
#include <ctype.h>
#include <stdio.h>
#include ".\code\stack\STACK.h"LCUL.H*/

/*CALCUL.PRJ*/
.\code\caculate\CALCUL.c
.\code\caculate\CALCUL.h
...全文
1528 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljy228 2007-05-16
  • 打赏
  • 举报
回复
/*stack.h*/
#ifndef _Stack_h
#define _Stack_h
struct Node;
typedef double ElementType;
typedef struct Node*PtrToNode;
typedef PtrToNode Stack;


int IsEmpty(Stack S);
Stack CreateStack(void);
void DisposeStack(Stack S);
void MakeEmpty(Stack S);
void Push(ElementType X, Stack S);
ElementType Top(Stack S);
void Pop( Stack S);

/*_Stack_h */
struct Node
{ ElementType Element;
PtrToNode Next;
};
#endif

/*stack.c*/
#include<stdio.h>
#include".\code\stack\stack.h"

void Error(char *);
void FatalError(char *);
int IsEmpty( Stack S)
{ return S->Next == NULL;
}

Stack CreateStack()
{ Stack S;
S=malloc(sizeof(struct Node));
if (S==NULL)
FatalError("Out of space!!!");
S->Next=NULL;
return S;
}

void MakeEmpty( Stack S)
{ if (S==NULL)
Error("Must use CreateStack first!");
else
while ( !IsEmpty(S))
Pop(S);
}
void Push(ElementType X, Stack S)
{ PtrToNode TmpCell;
TmpCell=malloc( sizeof( struct Node));
if( TmpCell == NULL)
FatalError("Out of space!!!");
else
{ TmpCell->Element = X;
TmpCell->Next = S->Next;
S->Next = TmpCell;
}
}

ElementType Top( Stack S)
{ if (!IsEmpty(S))
return S->Next->Element;
Error("Empty Stack");
return 0;
}

void Pop( Stack S)
{
PtrToNode FirstCell;
if (IsEmpty(S))
Error("Empty stack");
else
{
FirstCell = S->Next;
S->Next = S->Next->Next;
free( FirstCell);
}
}


void Error(char *m)
{ printf("%s",*m);
}
void FatalError(char *m)
{ printf("%s",*m);
}
void DisposeStack(Stack S)
{ S->Next=NULL;
S->Element=NULL;
free(S);
}
lightnut 2007-05-16
  • 打赏
  • 举报
回复
把你的stack.h和stack.c贴出来吧
ljy228 2007-05-16
  • 打赏
  • 举报
回复
还是不行。。。
lightnut 2007-05-16
  • 打赏
  • 举报
回复
/*CALCUL.C*/
#include<stdio.h>
#include".\code\stack\STACK.h"
#include".\code\caculate\CALCUL.h"

/*CALCUL.h*/

#ifndef _CLACUL_H_
#define _CLACUL_H_

#include <ctype.h>
#include <stdio.h>
#include ".\code\stack\STACK.h"
.....
#endif


/*STACK.h*/

#ifndef _STACK_H_
#define _STACK_H_

// your stack.h stuff
.....
#endif

ljy228 2007-05-16
  • 打赏
  • 举报
回复
还是不对
sinkileu 2007-05-16
  • 打赏
  • 举报
回复
试试把
#include".\code\stack\STACK.c"

中的.c改成.h

69,371

社区成员

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

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