-2
char puzzle[i][j];  
int i,j,count=0;  
char value[81];

for( i = 0; i < 9; i++){  
  for( j = 0; j < 9; j++){  
    cin >> value[count];  
    puzzle[i][j] = value[count];  
    count++;  
  }}

This what I have so far. I tried using atoi but I needed a char * str. The input is: ..4545.. (numbers and periods)
I'm trying to convert the char puzzle[i][j] to an int puzzle[i][j]. The char array currently holds "..4545.." and I want to covert it so it holds just integers "00454500".

Phil
  • 1
  • 1
  • 2
  • 1
    Downvoted because you didn't bother posting code that remotely looked like something compilable and that code is at odds with your unclear requirements. – Luc Danton Jul 04 '11 at 02:45
  • I see a two-dimensional `char` array, but no two-dimensional `int` array. I'm confused what you're trying to accomplish, and how the code relates to the stated problem. – sarnold Jul 04 '11 at 02:45
  • atoi won't work because puzzle is a char array for starters. –  Jul 04 '11 at 02:59

1 Answers1

3

Engaging psychic debugger...

Performing Jedi mind tricks...

This is the code you want:

int puzzle[9][9];  // changed type
int i,j,count=0;  
char value[81];

for( i = 0; i < 9; i++ ) {  
  for( j = 0; j < 9; j++ ) {  
    cin >> value[count];  
    puzzle[i][j] = value[count] - '0';  // convert from ASCII digit to integer
    count++;  
  }
}
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Where can I get myself a copy of that psychic debugger? – aib Jul 04 '11 at 03:45
  • 1
    @aib: Practice. With 275 answers you should have a psychic debugger of your own, although it may be very unreliable. Just don't let anyone use mind tricks on you and try to pay you in Republic credits. Insist on SO rep ;) – Ben Voigt Jul 04 '11 at 03:46
  • Never mind, turns out I already have a copy in my flash drive. Don't remember putting it there, though... – aib Jul 04 '11 at 03:47