Why do I get the following errors when I attempt to run it? I do not see any errors before/after line 6 or the other lines it references...
% gcc StackImplementation.c
StackImplementation.c:6: error: syntax error before '{' token
StackImplementation.c:11: error: syntax error before '{' token
StackImplementation.c:16: error: syntax error before '{' token
StackImplementation.c:21: error: syntax error before '{' token
StackImplementation.c:26: error: 'S' undeclared here (not in a function)
StackImplementation.c:26: warning: data definition has no type or storage class
StackImplementation.c:27: error: syntax error before '}' token
StackImplementation.c:31: error: syntax error before '{' token
vi StackImplementation.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include "StackInterface.h"
void InitializeStack(Stack *S);
{
S->Count = 0;
}
int Empty(Stack *S);
{
return (S->Count == 0);
}
int Full(Stack *S);
{
return (S->Count == MAXSTACKSIZE);
}
void Pop(Stack *S, ItemType *X);
{
if (S->Count == 0) {
SystemError("attempt to pop the empty stack");
} else {
--(S->Count);
*X = S->Items[S->Count];
}
}
void Push(ItemType X, Stack *S);
{
if (S->Count == MAXSTACKSIZE) {
SystemError("attempt to push item onto a full stack");
} else {
S->Items[S->Count] = X;
++(S->Count);
}
}
vi StackInterface.h
Code:
#include "StackTypes.h"
extern void InitializeStack(Stack *S);
extern int Empty(Stack *S);
extern int Full(Stack *S);
extern void Push(ItemType X, Stack *S);
extern void Pop(Stack *S, ItemType *X);
vi StackTypes.h
Code:
#define MAXSTACKSIZE 100
typedef float ItemType;
typedef struct{
int Count;
ItemType Items[MAXSTACKSIZE];
} Stack;
vi post.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include "StackInterface.h"
Stack EvalStack;
char *PostfixString;
void InterpretPostfix(void)
{
float LeftOperand, RightOperand, Result;
int i;
char c;
char *s= "x";
InitializeStack(&EvalStack);
for (i = 0; i < strlen(PostfixString); ++i) {
s[0] = c = PostfixString[i];
if (isdigit(c)) {
Push((float)atof(s),&EvalStack);
} else if (c == '+' || c == '-' || c == '*' || c == '/' || c == '^' ) {
Pop(&EvalStack, &RightOperand);
Pop(&EvalStack, &LeftOperand);
switch (c) {
case '+' : Push(LeftOperand + RightOperand, &EvalStack);
break;
case '-' : Push(LeftOperand - RightOperand, &EvalStack);
break;
case '*' : Push(LeftOperand * RightOperand, &EvalStack);
break;
case '/' : Push(LeftOperand / RightOperand, &EvalStack);
break;
case '^' : Push(exp(log(LeftOperand) * RightOperand), &EvalStack);
break;
default : break;
}
}
}
Pop(&EvalStack,&Result);
printf("Value of postfix expression = %f\n", Result);
}