digits to words

A

ARMAS

could you give me the rpogram in changing digits into words??
Ex: input:1435 output:eek:ne thousand four hundred thirty five......
 
U

user923005

ARMAS said:
could you give me the rpogram in changing digits into words??
Ex: input:1435 output:eek:ne thousand four hundred thirty five......

Yes, but DYOH!

If you show us your effort so far, we'll be glad to help. But we would
never harm you in such a way as to do your homework for you, therefore
robbing you of a quality education that is costing you so dearly.
 
B

Ben Pfaff

ARMAS said:
could you give me the rpogram in changing digits into words??
Ex: input:1435 output:eek:ne thousand four hundred thirty five......

Here's one I wrote a number of years ago.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *ordinal (char buf[1024], unsigned value);

int
main (int argc, char *argv[])
{
char buf[1024];

if (argc != 2)
{
printf ("usage: ordinal <number>\n");
return EXIT_FAILURE;
}

ordinal (buf, atoi (argv[1]));
puts (buf);
return EXIT_SUCCESS;
}

char *
ordinal (char buf[1024], unsigned value)
{
static const char *const powers[]
= {"man", "oku"};

static const char *const values[][9] =
{
{"sen", 0, "sanzen", 0, 0, 0, 0, "hassen", 0},
{"hyaku", 0, "sanbyaku", 0, 0, "roppyaku", 0, "happyaku", 0},
{"juu", 0, 0, 0, 0, 0, 0, 0, 0},
{"ichi", "ni", "san", "yon", "go", "roku", "nana", "hachi", "kyuu"},
};

static const char *const *const ones = values[3];

char *cp = buf;

if (value == 0)
{
strcpy (buf, "rei");
return buf;
}

{
int part_stack[4];
int *part_ptr = part_stack;

for (; value; value /= 10000)
*part_ptr++ = value % 10000;

while (part_ptr > part_stack)
{
int index[4];
int p, i;

p = *--part_ptr;
for (i = 3; i >= 0; i--)
{
index = p % 10;
p /= 10;
}

for (i = 0; i < 4; i++)
{
int c = index;
if (c != 0)
{
if (values[c - 1] == 0)
cp += sprintf (cp, "%s%s ", ones[c - 1], values[0]);
else
cp += sprintf (cp, "%s ", values[c - 1]);
}
}

if (*part_ptr && part_ptr > part_stack)
cp += sprintf (cp, "%s ", powers[part_ptr - part_stack - 1]);
}
}

cp[-1] = 0;
return buf;
}

/*
Local variables:
compile-command: "gcc -W -Wall -ansi -pedantic ordinal-jp.c -o ordinal-jp"
End:
*/
 
A

ARMAS

If you show us your effort so far, we'll be glad to help. But we would
never harm you in such a way as to do your homework for you, therefore
robbing you of a quality education that is costing you so dearly.
 
U

user923005

ARMAS said:
could you give me the rpogram in changing digits into words??
Ex: input:1435 output:eek:ne thousand four hundred thirty five......Here's one I wrote a number of years ago.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *ordinal (char buf[1024], unsigned value);

int
main (int argc, char *argv[])
{
char buf[1024];

if (argc != 2)
{
printf ("usage: ordinal <number>\n");
return EXIT_FAILURE;
}

ordinal (buf, atoi (argv[1]));
puts (buf);
return EXIT_SUCCESS;

}char *
ordinal (char buf[1024], unsigned value)
{
static const char *const powers[]
= {"man", "oku"};

static const char *const values[][9] =
{
{"sen", 0, "sanzen", 0, 0, 0, 0, "hassen", 0},
{"hyaku", 0, "sanbyaku", 0, 0, "roppyaku", 0, "happyaku", 0},
{"juu", 0, 0, 0, 0, 0, 0, 0, 0},
{"ichi", "ni", "san", "yon", "go", "roku", "nana", "hachi", "kyuu"},

{"ichi", "ni", "san", "she", ...

Unless there is a dialect I do not know about.
};

static const char *const *const ones = values[3];

char *cp = buf;

if (value == 0)
{
strcpy (buf, "rei");
return buf;
}

{
int part_stack[4];
int *part_ptr = part_stack;

for (; value; value /= 10000)
*part_ptr++ = value % 10000;

while (part_ptr > part_stack)
{
int index[4];
int p, i;

p = *--part_ptr;
for (i = 3; i >= 0; i--)
{
index = p % 10;
p /= 10;
}

for (i = 0; i < 4; i++)
{
int c = index;
if (c != 0)
{
if (values[c - 1] == 0)
cp += sprintf (cp, "%s%s ", ones[c - 1], values[0]);
else
cp += sprintf (cp, "%s ", values[c - 1]);
}
}

if (*part_ptr && part_ptr > part_stack)
cp += sprintf (cp, "%s ", powers[part_ptr - part_stack - 1]);
}
}

cp[-1] = 0;
return buf;

}/*
Local variables:
compile-command: "gcc -W -Wall -ansi -pedantic ordinal-jp.c -o ordinal-jp"
End:
*/
 
K

Keith Thompson

Please learn to quote properly. Those ">" characters aren't
decorative; they indicate that you're quoting something that someone
else wrote.

"you better work on it too"? I don't think so. If you ask for our
help, we might give it to you; if you demand it, you're on your own.
 
A

ARMAS

decorative; they indicate that you're quoting something that someone
else wrote.

"you better work on it too"? I don't think so. If you ask for our
help, we might give it to you; if you demand it, you're on your own.




I'm just a begginer... I'm sorry if i don't know that much... I've got
two words for you though: "suck it"
 
U

user923005

decorative; they indicate that you're quoting something that someone
else wrote.
"you better work on it too"? I don't think so. If you ask for our
help, we might give it to you; if you demand it, you're on your own.
two words for you though: "suck it"

Normally, you would have earned an almighty *plonk* but I can tell that
this is going to be *really* funny to watch, so I'll leave the door
open for a while.
 
K

Keith Thompson

ARMAS said:
"you better work on it too"? I don't think so. If you ask for our
help, we might give it to you; if you demand it, you're on your own.
[...]
I'm just a begginer... I'm sorry if i don't know that much... I've got
two words for you though: "suck it"

Thus endeth the lesson.
 
K

Kenny McCormack

could you give me the rpogram in changing digits into words??
Ex: input:1435 output:eek:ne thousand four hundred thirty five......

Here's pseudo-code to get you started:

IF input = 1 THEN puts("one");
IF input = 2 THEN puts("two");
IF input = 3 THEN puts("three");
IF input = 4 THEN puts("four");

Just keep going like this - it should not be too hard.
 
K

Kenneth Brody

ARMAS said:
could you give me the rpogram in changing digits into words??
Ex: input:1435 output:eek:ne thousand four hundred thirty five......

char *IntToEnglish(int i)
{
switch(i)
{
case 0: return "zero";
case 1: return "one";
case 2: return "two";
case 1435: return "one thousand four hundred thirty five";
default: return "unknown number";
}
}

Extend as needed.

Replace English words with Roman numerals for your other homework
problem. ie:

case 1: return "I";
case 2: return "II";
case 1435: return "MCDXXXV";

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
U

user923005

/* I say we give this poor kid a hand: */
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<float.h>
extern char*q0(long double q1);static void q2(int q1,char*q3);static
char q4??(1024??),*q5;static const char*q6??(??)=??<
"\132\
\145\162\157","\117\156\145","\124\167\157","\124\150\162\145\145",
"\106\157\165\162","\106\151\166\145","\123\151\170",
"\123\145\166\145\156","\105\151\147\150\164","\116\151\156\145",
"\124\145\
\156","\105\154\145\166\145\156","\124\167\145\154\166\145",
"\124\150\151\162\164\145\145\156","\106\157\165\162\164\145\145\156",
"\106\151\146\164\145\145\156","\123\151\170\164\145\145\156",
"\123\145\166\145\156\164\145\
\145\156","\105\151\147\150\164\145\145\156",
"\116\151\156\145\164\145\145\156"??>;static const char*q7??(??)=??<
"\124\167\145\156\164\171","\124\150\151\162\164\171",
"\106\157\162\164\171","\106\151\146\164\171","\123\151\170\164\171",
"\123\145\166\145\156\164\171","\105\151\147\150\164\171",
"\116\151\156\145\164\171"??>;typedef struct q8??<long double q9;char*
q10;??>q11;static const q11 q12??(??)=??<??<1e00,""??>,??<1e03,
"\124\150\157\165\163\141\156\144"??>,??<1e06,
"\115\151\154\154\151\157\156"??>,??<1e09,
"\102\151\154\154\151\157\156"??>,??<1e12,
"\124\162\151\154\154\151\157\156"??>,??<1e15,
"\121\165\141\144\162\151\154\154\
\151\157\156"??>,??<1e18,
"\121\165\151\156\164\151\154\154\151\157\156"??>,??<1e21,
"\123\145\170\164\151\154\154\151\157\156"??>,??<1e24,
"\123\145\160\164\151\154\154\151\157\156"??>,??<1e27,
"\117\143\164\151\154\154\151\157\156"??>,??<1e30,
"\116\157\156\151\154\154\151\157\156"??>,??<1e33,
"\104\145\143\151\154\154\151\157\156"??>,??<1e36,
"\125\156\144\145\143\
\151\154\154\151\157\156"??>,??<1e39,
"\104\165\157\144\145\143\151\154\154\151\157\156"??>,??<1e42,
"\124\162\145\144\145\143\151\154\154\151\157\156"??>,??<1e45,
"\121\165\141\164\164\165\157\162\
\144\145\143\151\154\154\151\157\156"??>,??<1e48,
"\121\165\151\156\144\145\143\151\154\154\151\157\156"??>,??<1e51,
"\123\145\170\144\145\143\151\154\154\151\157\156"??>,??<1e54,
"\123\145\160\164\
\145\156\144\145\143\151\154\154\151\157\156"??>,??<1e57,
"\117\143\164\157\144\145\143\151\154\154\151\157\156"??>,??<1e60,
"\116\157\166\145\155\144\145\143\151\154\154\151\157\156"??>,??<1e63,
"\
\126\151\147\151\156\164\151\154\154\151\157\156"??>??>;static void q2
(int,char*);char*q0(long double q1)??<int q14;int q15;int q16;long
double q17;long double q18=((long double)modf((double)(q1),(double*)(&
q17)));long double q19;*q4='\0';q5=q4;if(q1<0)??<q1=-q1;*q5='-';q5++;*
q5=0;??>q19=((long double)log10((double)(q1)));q16=((int)q19)/3;if(q16
21)??<puts("\105\162\162\157\162\41\40\40\125\156\141\142\154\145\40"
"\164\157\40\160\162\157\143\145\163\163\40\156\165\155\142\145\162"
"\163\40\164\150\
\141\164\40\154\141\162\147\145\56\n");exit(1);??>if(q19>15)??<puts(
"\127\141\162\156\151\156\147\41\40\40\114\157\163\163\40\157\146\40"
"\141\143\143\165\162\141\143\
\171\40\151\156\40\143\141\154\143\165\154\141\164\151\157\156\56\n");
??>for(q15=q16;q15>0;q15--)??<q14=(int)(q1/q12??(q15??).q9);if(q14)??<
q2(q14,q12??(q15??).q10);q1=((long double)fmod((double)(q1),(double)(
q12??(q15??).q9)));??>??>q2((int)q1,"");if(q4==q5)q5+=sprintf(q5,
"\45\163\40",q6??(0??));q14=(int)(q18*100.+.5);sprintf(q5,
"\46\40\45\60\62\144\57\61\60\60",q14);return q4;??>static void q2(int
q1,char*q3)??<if(q4!=q5)*q5++=' ';if(100<=q1)??<q5+=sprintf(q5,
"\45\163\40\110\165\156\144\162\145\144\40",q6??(q1/100??));q1%=100;
??>if(20<=q1)??<q5+=sprintf(q5,"\45\163",q7??((q1-20)/10??));if(0!=(q1
%=10))??<q5+=sprintf(q5,"\55\45\163\40",q6??(q1??));??>else q5+=
sprintf(q5,"\45\163","\40");??>else if(q1)??<q5+=sprintf(q5,
"\45\163\40",q6??(q1??));??>q5+=sprintf(q5,"\45\163",q3);??>int main(
int q20,char*q21??(??))??<while(--q20)??<long double q1=atof(*(++q21))
;printf(
"\146\155\164\137\155\157\156\145"
"\171\50\45\114\147\51\40\75\40\45\163\n"
,q1,q0(q1));??>return 0;??>
 
B

Ben Pfaff

user923005 said:
{"ichi", "ni", "san", "she", ...

Unless there is a dialect I do not know about.

I'm fairly sure about this, having taken a couple of years of
Japenese when I was an undergrad. If you want more information,
putting "shi yon" into Google is informative.
 
U

user923005

Japenese when I was an undergrad. If you want more information,
putting "shi yon" into Google is informative.

Quite right, I am hardly a Japanese expert. I only knew how to count
from martial arts classes.
Turns out it is (indeed) a synonym.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p\
);}return 0;}
 
L

Lew Pitcher

/* I say we give this poor kid a hand: */
[snip]

I agree. Let's all applaud the guy :)

To the OP, do you mean something that outputs results like...
pitchl@phantom:~/code/num2txt$ num2txt
1234567890 reads as "One Billion, Two Hundred Thirty Four Million,
Five Hundred Sixty Seven Thousand, Eight Hundred Ninety"
123456789 reads as "One Hundred Twenty Three Million, Four Hundred
Fifty Six Thousand, Seven Hundred Eighty Nine"
12345678 reads as "Twelve Million, Three Hundred Fourty Five
Thousand, Six Hundred Seventy Eight"
1234567 reads as "One Million, Two Hundred Thirty Four Thousand,
Five Hundred Sixty Seven"
123456 reads as "One Hundred Twenty Three Thousand, Four Hundred
Fifty Six"
12345 reads as "Twelve Thousand, Three Hundred Fourty Five"
1234 reads as "One Thousand, Two Hundred Thirty Four"
123 reads as "One Hundred Twenty Three"
12 reads as "Twelve"
1 reads as "One"
0 reads as "Zero"
?
 
D

Default User

ARMAS wrote:

I'm just a begginer... I'm sorry if i don't know that much... I've got
two words for you though: "suck it"


And I have one for you:

*plonk*





Brian
 
A

ARMAS

{
switch(i)
{
case 0: return "zero";
case 1: return "one";
case 2: return "two";
case 1435: return "one thousand four hundred thirty five";
default: return "unknown number";
}
}

Extend as needed.

Replace English words with Roman numerals for your other homework
problem. ie:

case 1: return "I";
case 2: return "II";
case 1435: return "MCDXXXV";

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |www.hvcomputer.com| #include |
| kenbrody/at\spamcop.net |www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>


hey , what i mean is, user gets to input any number, not just the
example.... are you making fun of me???
 
M

matevzb

I'm just a begginer... I'm sorry if i don't know that much... I've got
two words for you though: "suck it"
hey , what i mean is, user gets to input any number, not just the
example.... are you making fun of me???
Probably not. Methinks this is C code for "suck it".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top