I'm trying to create a dos-based sudoku solving program. The first step, as you can see in the code here, is to collect user input. The primary responsibility of the function "checkValid" is to collect each row of the puzzle to be solved and check for invalid input - (For example entering more than one of a certain value in a particular row).
The code here compiles without any errors or warnings. I run the program and, as expected, I am immediately prompted to input the first row of values. However as soon as I finish the first input I get a Windows error: "program has stopped working".
What is wrong with the checkValid function or the program in general that is causing this error?
Code:
#include <iostream>
#include <string>
using namespace std;
bool checkValid(char*& chkd) { //Checks validity of user input.
cin.getline(chkd, 10); /*USER WILL BE PROMPTED TO ENTER '#" FOR EMPTY CELLS.*/
bool j = true;
string cts = chkd; //Passed to sizeof to return amount of characters.
int q = 9;
if(sizeof(cts) != q)
{
cout << "You must enter exactly 9 characters." << endl;
j = false;
} else
{
for(int nS = 1, a = 0; nS < (q + 1); nS++)
{
for(int nA = 0; nA < q; nA++)
{
if(chkd[nA] == nS) a++;
if(a > 1) //<-Determines if more than one of a
{ //certain value is present in a row or column.
j = false;
break;
}
}
if(j == false) break;
}
}
return j;
}
int main(int argc, char *argv[])
{
//Rows to be implemented.
char * r1 = "";
char * r2 = "";
char * r3 = "";
char * r4 = "";
char * r5 = "";
char * r6 = "";
char * r7 = "";
char * r8 = "";
char * r9 = "";
for(int nDict = 1; nDict < 10; nDict++)
{
again:
bool b = true;
switch(nDict)
{
case 1: if(checkValid(r1)) break; else { b = false; r1 = ""; break;}
case 2: if(checkValid(r2)) break; else { b = false; r2 = ""; break;}
case 3: if(checkValid(r3)) break; else { b = false; r3 = ""; break;}
case 4: if(checkValid(r4)) break; else { b = false; r4 = ""; break;}
case 5: if(checkValid(r5)) break; else { b = false; r5 = ""; break;}
case 6: if(checkValid(r6)) break; else { b = false; r6 = ""; break;}
case 7: if(checkValid(r7)) break; else { b = false; r7 = ""; break;}
case 8: if(checkValid(r8)) break; else { b = false; r8 = ""; break;}
case 9: if(checkValid(r9)) break; else { b = false; r9 = ""; break;}
}
if( b == false) goto again;
}
}