Hm.... I hate to be that guy who just comes into a thread when he has a question but.... well, I've got another code that isn't executing properly. Right now, after entering the numbers, the program will just immediately crash.
It's supposed to be able to add two ten-thousand digit numbers(I've got it set up to test with smaller numbers for obvious reasons), and it should be able to at least handle adding numbers that don't need carrying(I'm still working that part out- right now I just want to get it to work on numbers like 12+12, then I'll fine tune that part).
#include #include #include int main(){ char firstNumber[2], secondNumber[2], totalNumber[2]; int counter='1'; char digitIndicator='1'; char* charSum="0"; int digitOne, digitTwo, intSum, carry; printf("Enter your first number here:"); fgets(firstNumber, 11111, stdin); printf("Enter your second number here:"); fgets(secondNumber, 11111, stdin); for(counter; counter>=0; counter--){ digitTwo=secondNumber[digitIndicator]-'0'; digitOne=firstNumber[digitIndicator]-'0'; // supposed to find a single element in a string(e.g. '1' in 31), and convert it to int; I found it on the 'net, so I'm not sure if it might be contributing to problems intSum=digitTwo+digitOne; if(intSum<10){ sprintf(charSum, "%d", intSum); strcat(totalNumber, charSum); digitOne=0; digitTwo=0; } else if(intSum>10){ carry=intSum%10; sprintf(charSum, "%d", carry); strcat(totalNumber, charSum); digitOne=1; digitTwo=0; } digitIndicator--; } strrev(totalNumber); printf("%s", totalNumber); return 0;}