I'm trying to take in a simple command line argument in a C++ program to trigger different program behavior - when you include a "y" (or any string starting with y - I don't really care) the program displays some intermeadiate results.
When I run with
ccal pix.txt
everything works fine.
When I use
ccal pix.txt yes
It runs OK, shows my pix and crashes at the very end.
Also,
ccal pix.txt no
runs everything OK without showing pix (like it should), and still crashes at the very end.
Here's the relevant code - what am I doing wrong?
void dumpFloatMatrix(Mat m){
for(int i = 0; i < m.cols; i++){
for(int j = 0; j < m.rows; j++){
char *buff = new char[10];
sprintf(buff, "%5.1f ", m.at<float>(i,j));
cout << buff;
delete buff;
}
cout << endl;
}
}
int main(int argc, char *argv[]){
char* outFile;
bool showPix = false;
// Take in command line args
switch(argc){
case 3:
if(strncmp(argv[2], "y", 1) == 0)
showPix = true;
outFile = argv[1];
break;
case 2:
outFile = argv[1];
break;
default:
cout << "Usage: ccal INPUT_LIST_FILE" << endl;
return -1;
}
Mat cameraMatrix(3, 3, CV_32FC1);
dumpFloatMatrix(cameraMatrix);
return 0;
}
The weird thing is that even when I switch the test in case 3 to something like this:
if(argv[2][0] == 'y')
I still get the same behavior. I can't for the life of me figure out why.