1. printing in words

hello sir
first of all i wish every board members a happy xmas and a happy new year.my wishes to salem in advance.
sir,iam a beginner to c program.i want to know whether there is any way that we could print in words the digit i inputted, ie if i enter 45 the o/p should be forty five and if it is 1234 it should be one thousand two hundred and thirty four, like on.
with warm wishes and thanks in anticipation
have a nice day.

2. What you would want to do is also read in the digit place. For example, if it is in the 10ths place, the that would be a certain ending. You see? I think it would just be a lot of switch or else-if statements. If is however you want to do it.

--Garfield

3. you might use an array of char *strings, {"Forty "},{"Fifty"}, ...
Parse the input, into an array maybe a linked list.
I think the basic algorithm is that each length is measured and thus assigned a "magnitude", then reverse iterated through. The "tail" end is the tens place and so on.

123456[7]<--start here

Reassemble input string and display in it's new format.

what do you have so far?

4. Try this. It should be fairly simple to convert the remaining numbers to text.

Code:
```#include <stdio.h>
#include <string.h>

/*************************** FUNCTION PROTOTYPES *******************************/

void NumToWord(double num);
void ParseNum(char *strnum, int i, int level);
void PrintIt(char *str, int level);

/*******************************************************************************/

int main(void)
{
double num;

// test data
num = 12345678901.23;
NumToWord(num);

printf("\n");

// test data
num = 123456.78;
NumToWord(num);

printf("\n");

//test data
num = 1234567890123.45;
NumToWord(num);

return 0;
}

void
NumToWord(double num)
{
int i;
int level = 0;		// used to determine what string to print in "PrintIt"
char cents[3];
char strnum[21];	// working variable; make sure variable is large enough!

sprintf(strnum, "%.2f", num);	// make sure the double has only 2 decimal places

i = strlen(strnum);

do								// find the period, if it exists
{
i--;
}
while (i && strnum[i] != '.');

if (i)							// found a period, parse out the "cents" amount
{
strncpy(cents, strnum+i+1, 2);
cents[2] = '\0';
strnum[i] = '\0';
}

ParseNum(strnum, i, level);		// start parsing the whole amount

PrintIt(cents, 6);
}

void
PrintIt(char *str, int level)
{
switch (level)
{
case 1:
printf(" %s Dollars ", str);
break;

case 2:
printf(" %s Thousand ", str);
break;

case 3:
printf(" %s Million ", str);
break;

case 4:
printf(" %s Billion ", str);
break;

case 5:
printf(" %s Trillion ", str);
break;

case 6:
printf(" and %s cents", str);
break;
}
}

void
ParseNum(char *strnum, int i, int level)
{
char str[4];

if (i >= 3)
{
str[0] = strnum[i-3];
str[1] = strnum[i-2];
str[2] = strnum[i-1];
str[3] = '\0';
strnum[i-3] = '\0';
i -= 3;

level++;

if (i)
ParseNum(strnum, i, level);	// not done, recursive call to parse again

PrintIt(str, level);
}
else if (i == 2)
{
str[0] = strnum[i-2];
str[1] = strnum[i-1];
str[2] = '\0';

level++;
PrintIt(str, level);
}
else if (i == 1)
{
str[0] = strnum[i-1];
str[1] = '\0';

level++;
PrintIt(str, level);
}
}```