Getting a large number

Hello,

I am trying to recieve a large number from the user and doing some manipulation on it.
The number is 15 digit long. I tried to save as an int but it's too small.
I also tried to save as a long int, unsigned int and it's still to small.

Do you have any suggestions what can I do?
Thanks.
pull it in as a string. Not sure what manipulation you're trying to do, but you'll need to pull the number itself in as a string.
This is a hell of a data type... But it should work up to 20 digits: unsigned long long int

From what I have understood "long long" is not supported by all compilers, but on dev-cpp (MinGW) it works fine.
Last edited on
Thanks, guys.
But the thing is I need to do it in C, not C++.
Any ideas?
Well, I'm not familiair with datatypes in C, but you could use the solution jpeg suggested. I know you cant use strings, but an array of chars would work. After you got the input, you can convert it to an array of integers and create functions to perform the required operations.

I bed there is an easier solution, but I dont know it :)
1. unsigned long long int
2. Store it as a string
3. Store it as BCD
4. Store it as a bignum

Option two means you have to add/subtract/multiply/etc strings.
Option three is really just a much more convenient variation of option two.
Option four is what I suggest. You can either roll your own, or just go straight to the GNU MP Bignum Library. http://gmplib.org/

Hope this helps.
Topic archived. No new replies allowed.