This is my first time on this forum. I have to make this program check for balanced parentheses. I have most of the work done. But i keep getting "cannot convert `int*' to `STACK*' for argument `1' to `void push(STACK*, int)' ". I marked where errors are in program. I believe i am not implementing the functions right please any help would be greatly appreciated. I know its probably something dumb and small.
Thanks alot in advance for any help
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
char* filename;
#define MAX 300
typedef struct stack
{
int item[MAX];
int Top;
}STACK;
void push(STACK *ps, int x)
{
if (ps->Top == MAX) {
fputs("Error: stack overflow\n", stderr);
abort();
} else
ps->item[ps->Top++] = x;
}
int pop(STACK *ps)
{
if (ps->Top == 0){
fputs("Error: stack underflow\n", stderr);
abort();
} else
return ps->item[--ps->Top];
}
int main ()
{
size_t found;
string str, tmp;
cout <<"Please enter the name of the file" << endl;
filename=new char;
cin >> filename;
ifstream myfile(filename);
while(!myfile.eof())
{
getline(myfile, tmp);
str += tmp;
}
int array[300];
found=str.find_first_of("(");
while (found!=string::npos)
{
str[found]='*';
found=str.find_first_of("(",found+1);
push(array, 1); // error
}
found=str.find_first_of(")");
while (found!=string::npos)
{
str[found]='*';
found=str.find_first_of(")",found+1);
pop(array, 1); // error
}
found=str.find_first_of("{");
while (found!=string::npos)
{
str[found]='*';
found=str.find_first_of("{",found+1);
push(array, 1); // error
}
found=str.find_first_of("}");
while (found!=string::npos)
{
str[found]='*';
found=str.find_first_of("}",found+1);
pop(array, 1); // error
}
found=str.find_first_of("[");
while (found!=string::npos)
{
str[found]='*';
found=str.find_first_of("[",found+1);
push(array, 1); // error
}
found=str.find_first_of("]");
while (found!=string::npos)
{
str[found]='*';
found=str.find_first_of("]",found+1);
pop(array, 1); // error
}
return 0;
}