Argh! That "expected unqualified-id before '[' token" is back for no apparent reason.
My new code:
main.cpp
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctype.h>
#include <stdlib.h>
#include "myStack.h"
using namespace std;
int main(int argc, char *argv[]) {
myStack stack1;
int arg_length;
char current_digit;
if(argc < 2) {
cerr << "Bad command line argument.\n";
exit(1);
}
arg_length = strlen(argv[1]);
if(arg_length > 9) {
cerr << "Bad command line argument.\n";
exit(1);
}
for(int ii = 0; ii < arg_length; ii++) {
current_digit = argv[1][ii];
if(!(isdigit(current_digit))) {
cerr << "Bad command line argument.\n";
exit(1);
}
}
stack1.setStackSize(atoi(argv[1]));
stack1.cc = 0;
while(getline(cin, stack1.aa[stack1.cc])) {
if(stack1.aa[stack1.cc].length() > 80)
cerr << "Bad input.\n";
else if(stack1.aa[stack1.cc][0] == '<')
stack1.pop(stack1.cc);
else if(stack1.aa[stack1.cc][0] == '>')
stack1.push(stack1.cc);
else if(stack1.aa[stack1.cc].length() == 0)
exit(0);
else
cerr << "Bad input.\n";
}
system("Pause");
return 0;
}
myStack.cpp
Code:
#include <iostream>
#include <string>
#include "myStack.h"
using namespace std;
void myStack::setStackSize(int x)
{
stackSize = x;
if(!(aa = new(nothrow) string[stackSize+1]))
cerr << "Program cannot handle a stack of size " << stackSize << ".\n";
}
void myStack::pop(int p) {
if(p == 0)
{
cout << "Empty stack.\n";
}
else
{
cout << aa[p-1];
cc--;
}
}
void myStack::push(int p)
{
if(p == stackSize)
{
cerr << "Full stack.\n";
}
else
{
aa[p] = aa[p].substr(1, aa[p].length());
aa[p] += "\n";
cc++;
}
}
myStack.h
Code:
/* myStack.h */
#ifndef HEADER_H
#define HEADER_H
#include <string>
class myStack
{
public:
std::string (*aa);
int stackSize;
int cc;
void setStackSize(int);
void pop(int);
void push(int);
int displayStackSize();
};
#endif