Say I got a number, I enter it in. (like 5). Now I want to convert that to a text string that represents that number (five).

I also want it so that if I were to print a big number like 543 or something it will print that out in its text format.

You could just add '0' to each of your numbers.

commented: WUT? -2

If you only want to convert integers to a string, then you should try itoa :)

What a way of missing the boat!
None of your suggestions are a solution.
The OP wants to have it display as a text.
e.i. 5 = Five, 6 = Six

tux4life> [...] then you should try itoa
I hope you understand that itoa is not a standard C function.

tux4life> [...] then you should try itoa
I hope you understand that itoa is not a standard C function.

Yes I know, thus actually this was a bad suggestion :(

What a way of missing the boat!
None of your suggestions are a solution.
The OP wants to have it display as a text.
e.i. 5 = Five, 6 = Six

You're totally right, I didn't read his question carefully enough :(

The simplest solution I know is by putting all the text representations of a number into an array, like this:

char *num[] = {
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten"
/* And so on ... */
};

Now if you want to convert the number 5 for example to "five" and display it on the screen, you just add the following line to your code: printf("%s\n", num[5]);

Also if your looking for large numbers lets say 5400 and you want to write five thousand you could count the digits. So the number 5 is the forth number from the end which makes it easy to determine it represents 5 thousand. The number 4 is three digits in so it represents hundres etc..

Also if your looking for large numbers lets say 5400 and you want to write five thousand you could count the digits. So the number 5 is the forth number from the end which makes it easy to determine it represents 5 thousand. The number 4 is three digits in so it represents hundres etc..

Yes, but apply the same rule to 15000, 1500, 150 and 15, what now?

>Yes, but apply the same rule to 15000, 1500, 150 and 15, what now?
It works fine? As long as you have the right special cases for identifying a teen and ignoring zeros, all is well with _Nestor's logic.

>Yes, but apply the same rule to 15000, 1500, 150 and 15, what now?
It works fine? As long as you have the right special cases for identifying a teen and ignoring zeros, all is well with _Nestor's logic.

Oh, as I'm not a native speaker I forgot about the English language rules for forming a number, if you write a program which can successfully apply these rules, it's all OK :)

And of course such a converter is better than just storing all text-representations in every way, for example it doesn't take up a lot of memory (this is rather for big numbers), you won't have to put all your effort in manually inputting all the text-representations of each number :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.