How to convert a 2d char array to a 2d int array?
-
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".
-
Answer:
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++; } }
Phil at Stack Overflow Visit the source
Related Q & A:
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- How to convert a char array into an int in C++?Best solution by Stack Overflow
- How do I add to an array from a static method?Best solution by stackoverflow.com
- How to convert a video to a specific format?Best solution by Super User
- How to convert a DC locomotive to a DCC locomotive?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.