I need to save a user input into a 2D array in a way where the user inputs something like '123456789' and I save that input into an array so that array[0][0] == 1, array[1][2] == 6 etc. Is there something like getchar() that I could use, but for numbers?
Asked
Active
Viewed 77 times
1 Answers
0
You can use getchar() itself, and convert it to integer using:
char c = getchar();
int arr[3][3];
arr[0][0] = c - '0';
Refer this stackoverflow answer.

Bharat S
- 334
- 1
- 8
-
Make it a habit of always using `int` with `getchar()`, since it can return `EOF`. – Lundin Mar 26 '21 at 12:50