Fix up the add() function to support variable-length numbers
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
1a6e740f28
commit
8e36ea0ab3
@ -8,6 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int main(int argc,char**argv) {
|
int main(int argc,char**argv) {
|
||||||
|
printf("%s",add((struct String){7,"1845920"},(struct String){4,"1829"}).str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ struct String add(struct String numb1, struct String numb2){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int offset=0;offset<numb1.length;offset++) {
|
for (int offset=0;offset<numb2.length;offset++) {
|
||||||
str = realloc(str,++digitCount);
|
str = realloc(str,++digitCount);
|
||||||
//printf("Digit count is now %d\n",digitCount);
|
//printf("Digit count is now %d\n",digitCount);
|
||||||
if (numb1.length>offset) {
|
if (numb1.length>offset) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user