I am trying to read a string of 9 characters into 9 integer values, to be stored in an array (for now I store them in 9 separate ints, will put them in the array once they read in OK). General approach i took: con the string, split it into 9 character values, convert (atoi) each into an integer and store as 9 ints, put the ints into the array. What is strange is, while the single values get split into the single characters with no problems, atop somehow "sees" the other neighboring values (not contained in that character at all!) and converts them backwards.
sample code:
countrows = 1;
countcols = 1;
cout << endl << "Enter values for boxes in row " << countrows << ", enter 0 for open boxes (enter 9 numbers, with no spaces or delimiters): ";
string inputline;
cin >> inputline;
char col1, col2, col3, col4, col5, col6, col7, col8, col9;
int int1, int2, int3, int4, int5, int6, int7, int8, int9;
col1 = inputline[0];
col2 = inputline[1];
col3 = inputline[2];
col4 = inputline[3];
col5 = inputline[4];
col6 = inputline[5];
col7 = inputline[6];
col8 = inputline[7];
col9 = inputline[8];
int1 = atoi(&col1);
int2 = atoi(&col2);
int3 = atoi(&col3);
int4 = atoi(&col4);
int5 = atoi(&col5);
int6 = atoi(&col6);
int7 = atoi(&col7);
int8 = atoi(&col8);
int9 = atoi(&col9);
cout << "inputline: " << inputline << endl;
cout << "col1: " << col1 << " col2: " << col2 << " col3: " << col3 << endl; //debug line
cout << "int1: " << int1 << " int2: " << int2 << " int3: " << int3 << endl; //debug line
the result of this is:
Enter values for boxes in row 1, enter 0 for open boxes (enter 9 numbers, with no spaces or delimiters): 456123789 inputline: 456123789 col1: 4 col2: 5 col3: 6 int1: 4 int2: 54 int3: 654
why does int contain 5 and int3 65 (should be int1: 4 int2: 5 int3: 6)