>I'm not sure how I could "split" a number
It's probably going to be easier to convert the number into a string using sprintf and then walk the string and print out the word value. Let's say you have 76328. You start on the left so that everything prints out nicely. 7 is the ten thousands place, so you print out "seventy" since 7 is equivalent to the tens place. Then you move forward to the thousands place and print "six", then "thousand". Move forward to the hundreds place and print the value of the digit, "three", then the value of the place, "hundred". Move forward to the tens place and print "twenty", then forward again to the ones place and print "eight". The result is "seventy six thousand three hundred twenty eight". Which is preciesly what you want. You'll notice a pattern here, the numbers pair into twos:
<tens> <ones>
Then you simply tack on further qualifiers after you handle the base cases: hundred, thousand, million, billion, etc... To convert to a number you perform the same process, this time using strcmp instead of testing a single character. For the actual implementation you could have a couple of tables such as one for the base cases and one for further qualifiers:
Code:
struct digit {
const char *word[9];
int number[10];
};
struct digit base[] = {
/* Ones */
{
{"one", "two", "three", ..., "nine"},
{1,2,3, ... , 9},
},
/* Tens */
{
{"ten", "twenty", thirty", ...., "ninety"},
{10, 20, 30, ..., 90},
},
};
Then you only have to handle the special case of the teens and use a counter to find the big stuff. Start at 0, increment to 1 and you're at the hundreds, increment to 2 and you're at the thousands. Lather, rinse, repeat.