Well there's a much simpler way to do this: Just keep the input as a string!
Here, one loop:
Code:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char *english[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
char input[BUFSIZ];
int i;
printf("Enter the number: ");
fflush(stdout);
fgets(input, sizeof(input), stdin);
for(i = 0;input[i] && input[i] != '\n';++i)
if(isdigit(input[i]))
puts(english[input[i] - '0']);
else
puts("unknown");
return 0;
}
Code:
itsme@itsme:~/C$ ./numtoenglish2
Enter the number: 1234567890,123948
one
two
three
four
five
six
seven
eight
nine
zero
unknown
one
two
three
nine
four
eight
itsme@itsme:~/C$