The night of my last reply, I went home and wrote a function which accomplished the task in about 300 lines of code. I am happy to report that, no longer being a newbie, it took me one hour to write it! Though it does contain some bugs, it otherwise works well.
I'll explain a little of how I approached it:
-First, if the input is a string, erase all whitespace.
-Find the length of the string. This will tell you right away the range of the number.
-Start backwards. That is, assemble the output string starting with the largest values.
-Use strcat frequently!
There will be several tricky manipulations. For instance, when you are processing, say, the "tens" place, you might need to do something like:
Code:
switch(input[i])
{
case '9': strcat(output, "Ninety ");
break;
///continue down the line
case '1':
ones_place_flag = 0; /* <--- make sure we don't get a string that ends up like : " Eighteen Eight Dollars" !!! */
switch(input[i+1])
{
case '9': strcat(output, "Nineteen ");
break;
// continue on down
...So that when you get to the ones place, you can use the "ones_place flag":
Code:
if(ones_place_flag != 0)
{
switch(input[i])
{
case '9': strcat(ouput, "Nine ");
break;
/// And so on...
You will probably use several of these types of flags....
Anyway, I hope that helped some. Let me know how it goes...