I'm looking to be able to parse the individual digits from a large integer using modulus and division such as in the code below (which was an answer to the same question on another thread.
Example:
Input: 123456789
9
8
7
6
5
4
3
2
1
Code:
#include <stdio.h>
int main(void)
{
int a = 12345;
do
{
printf("%d\n", a % 10);
}
while (a /= 10);
return 0;
}
This code works fine for when you have integers less than 10 digits. But say i was trying to parse a 20 digit int, it gives odd results.
Example:
Input: 123456789123456789
Output:
-5
-1
-3
0
-3
-6
-5
-9
-3
-1
I'm trying to do this as a way to parse a 20 digit int of 1's and 0's into an array so i can compare individual values.
Also im new to the forum, sorry if my the code is posted incorrectly