here's my task: I want to sum the digits of an int, problem is I don't know how many digits there are (and I can't ask the user). Is there anything like a getchar for int? I've also tried int c = getchar(), but it isn't working. Thanks:)
I wanted it to be a recursive function, but I guess it is just wrong.
I THINK I GOT IT, THANKS EVERYONE!
int sum_digits (int n) {
int answer = 0;
if (getchar() == 0) {
return answer;
}
else {
int c = getchar();
return answer = c + sum_digits(n);
}
}