This function treats two strings like they are ints and adds them. But the code looks long and has too many temporary variables for my liking. It is also confusing to try and follow. Can any one come up with a better way of doing this? Oh, and the checkstring function call just makes sure there are no letters or symbols in the string, just numbers.
Add exception catching or error checking for invalid strings as you like. If you feed it strings representing really big numbers it won't work, though. Do you need that too?
Well, yes... the point of this exercise was to be able to add numbers that are too big for ints, numbers of near infinite length. The kind of numbers that codechef makes you deal with...
It is going to be part of a new class I am working on called infInt (short for infinity int.)
@Manga,
IMO it's better to focus on writing code that is easily understandable, fast, testable, maintainable, extendible even it is more verbose.
For example the Dependency inversion principle is an important SOLID priciple, but adding additional classes and interfaces will lead to more code.
the point of this exercise was to be able to add numbers that are too big for ints
There was a thread about this a long time ago... http://www.cplusplus.com/forum/lounge/32041/
Might provide some inspiration. In particular, fun2code's idea to use a radix of 10000 is really nice,
as it combines performance (vs radix 10) and easy parsing / printing (vs a 2^n radix).