Thread: Help Please "array stack"

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    Help Please "array stack"

    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;
    }
    Last edited by seanman13579; 03-22-2011 at 12:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can I have an "Array of Strings"?
    By abh!shek in forum C++ Programming
    Replies: 15
    Last Post: 01-22-2008, 01:35 PM
  2. Replies: 1
    Last Post: 12-08-2007, 10:49 PM
  3. "array does not point to an object type"
    By Welshy in forum C Programming
    Replies: 2
    Last Post: 02-27-2006, 02:06 PM
  4. Essentially an "array of pointers" problem
    By Matt13 in forum C Programming
    Replies: 4
    Last Post: 03-12-2004, 03:36 AM