I think you should read your pointed answer and then try to emulate some of the code.
Most likely here the problem is, as was in your pointed answer, integer overflow.
Upon reading the long long
declaration, C is only forced to allocate the space it thinks it should; by other words, depending on the platform, long long could allocate a variable amount of bytes, being no shorter that the limit set by the C convention.
This post should enlighten you about this particular aspect of the language.
On another note, and assuming you passed to C++, you could use a dedicated Decimal
class to store the number's digits, then removing the long long int
memory size problem.
About the runtime error, C isn't required to even alert if you are trying to write data that isn't allocated. Suppose you had a unsigned int
(that by definition can store at least a number between 0 and 65535 (see this)). If you try to write a number higher that that, say 70000, C will happily write that; however the int you declared will store a absurd number. What happened was that to write 70000, C had to write a byte more than the int
could hold. It will write, but the result will be garbage.
It will only give a runtime error if you tried to access and write on to "protected" memory.
You can also try to use unsigned long long int
that (for a compiler following the C99 standard) is guaranteed to hold at least a number between 0 and 18446744073709551615.