How to convert a 2d char array to a 2d int array?

后端 未结 1 1025
温柔的废话
温柔的废话 2020-12-22 13:35
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]         


        
1条回答
  •  北海茫月
    2020-12-22 14:18

    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++;  
      }
    }
    

    0 讨论(0)
提交回复
热议问题