Hi everyone!
I've got a seemingly simple project for school in which we have command line tool that needs to add two large integers that get passed to me as arrays. NO LIBRARY FUNCTIONS ALLOWED! No malloc, nothing!
I've run into a problem when i need perform a carry operation on the final digit (the highest order digit) because there is no space left in the array. In java or C# I would just make a new array that is one larger and loop the old values into the new array, however, I can't really figure out how to get this to work in C. Here is the method signature
int* large_add(int* input1, int* input2)
where input1 and input2 are arrays that come from main().
In the end I tried making a new int array called temp and tried to return it in any way i could think of. Including the following
return temp;
return *temp;
return &temp;
return temp[0];
but I'm always getting warnings, and in any case the carry digit never shows up when the program prints the final result.
So, what I would really like to know is first (1) How do you return a local variable? Is this a smart thing to do in C? and (2) How can I change the size of input1? (I do the calculations on input1 instead of creating a new array because I can't seem to do it right...) and (3) if I am passed int* input1 and int* input 2 as formal parameters, how can i make a new array (called "result" for example) and then return it as int* ?
Thanks,
Jim