I almost read all of the articles about my problem in stackoverflow but they didn't solve it. I want a program that sums all the numbers in a string and shows me result. For example, when I write "a2s23l", it shows me 2 + 2 + 3 = 7 on screen. I wrote this:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
char input[15];
printf("Write smth: ");
gets(input);
int i, result = 0;
for(i=0; i<=15; i++)
{
if(isdigit(input[i]) != 0)
{
result = result + atoi(input[i]);
}
}
printf("Your result: %d", result);
return 0;
}
this is not working. I think there's something wrong about atoi function. Can you guys help me about this?