I'm having occasional errors when testing my program, I'm not quite sure. When this error occurs creates stackdump then will continue to produce the same error until I delete the stackdump.
only thing I could find on stackdump was:
http://www.cplusplus.com/forum/general/4282/
which was completely useless. What is a stackdump?
Unfortunately the error didn't point to any specific line being it was exec, which is usually what I read when looking at errors it said something about char * std:: alloc etc..
I didn't quite get it .... hit the enter key too soon and ended up back in VI, and unfortunately being that I was using VI opening shell, when I quit to go check the error again it had scrolled off the term. I have tried to reproduce the error but it is not comming up at the moment, I assume I will get it again sooner or later I hope so i can try and figure out what is going on. There is only 1 if statement that it seemed to happen on a few times.
This is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include "header.h"
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc,char *argv[])
{
int row=1;
string iparam="";
string oparam="";
string usage="Usage: -i \"input_file\" -o \"output_file\"";
// check if args have been supplied
if (argc<=1)
{
cerr << usage << endl;
exit(1);
}
// check switches
else if (argv[1][0] != '-')
{
cerr << "invalid switch: " << argv[1] << endl;
cerr << usage << endl;
exit(1);
}
// stick in/out elements in string iparam/oparam
while ((row<argc)&&(argv[row][0]=='-'))
{
string sw = argv[row];
if (sw =="-i")
{
row++;
iparam=argv[row];
}
else if (sw=="-o")
{
row++;
oparam=argv[row];
}
else
{
cerr << "unknown switch: " << argv[row] << endl;
cerr << usage << endl;
exit(1);
}
row++;
}
// check for duplicate filenames
if (iparam==oparam)
{
cerr << "Duplicates found, use unique files." << endl;
cerr << usage << endl;
exit(1);
}
// this is the "if" i introduced that started giving me the errors
// I had the previous code working and tested multiple times
// before implementing this next conditional.
// exit on more args than required:--
if (argv[5][0]!=0)
{
cerr << "Too many args." << endl;
cerr << usage << endl;
exit(1);
}
// start app:
StringSort ss(iparam,oparam);
ss.runApp();
}
|
The bottom if or possibly the creating of StringSort object most likely causes, I don't think it would be the object because at the moment all it is taking iparam and oparam as constructor args and setting them, with a couple cout test statements in constructor, setters, and runApp...
I'll post back if I come across the error again, I just don't want to submit this knowing the code may be flawed, something I may be overlooking...
Thanks for reading so far.