Here is my code:

void

do_print(int varnum, int *var) {

printf("register %c: ", varnum+CH\_A);

int i = 0;

while(*var>0){

v[i] = *var%10;

*var/= 10;

i++;

}

I am trying to store each digits of a number into an array, but when I tried very large number such as 12478783917289471284, the answer is incorrect. I know to convert it into a string, but when I changed the type int var to char var, the previous code which uses this function generates an error. The previous code is:

if (optype == PRINT) {

do_print(varnum, vars+varnum);

Is there a way to change vars+varnum back to int?

How can I store very large number into a string in C?

Thank you!

There are several free libraries available for calculating with big numbers in c. Google c bignum library to see a few.

commented: This. The first library that came to my mind as well was BIGNUM. +0
commented: Without using a library, instead using the approach of storing each digit in an array.... Is that possible? +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.