う~ん残念、最後の ninty-nine が合わない(BorlandC++5.5.1)。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HYAKU 4
char c3step[ 5 ][ 16 ] = {
"billion ", "million ", "thousand ", "", "hundred"
};
char c0019str[ 20 ][ 16 ] = { // 00 - 19
"", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
};
char c2099str[ 10 ][ 16 ] = { // 20, 30, ,,90
"", "",
"twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety"
};
void main( void )
{
char cStr[ 4 ][ 32 ] = {
"123", "34445", "432143213", "999432143100" };
char cWork[ 16 ] = { 0 }, cDumm;
int i, k, m, iLen, i100, i10, i1, iOn;
for( i = 0; i < 4; i++ ){
iLen = strlen( cStr[ i ] ) - 1;
for( k = 11; k >= 0; k-- ){ // cWork 後ろ詰め
cWork[ k ] = '*'; // 0x2A
if( iLen < 0 ) continue;
cWork[ k ] = cStr[ i ][ iLen-- ];
}
printf( "%s\n", cWork );
for( iOn = 0, m = 0; m < 4; m++ ){
i100 = cWork[ m * 3 ] - 0x30; // 0x2A - 0x30
if( i100 > 0 ){
iOn++;
printf( "%s %s ", c0019str[ i100 ], c3step[ HYAKU ] );
}
cDumm = cWork[ m * 3 + 3 ];
cWork[ m * 3 + 3 ] = '\0';
i10 = atoi( &cWork[ m * 3 + 1 ] );
cWork[ m * 3 + 3 ] = cDumm;
if( ! iOn && ! i10 ) continue;
if( i10 < 20 ){
printf( "%s %s", c0019str[ i10 ], c3step[ m ] );
continue;
}
i1 = i10 % 10;
i10 /= 10;
printf( "%s", c2099str[ i10 ] );
if( i1 ) printf( "-" );
printf( "%s %s", c0019str[ i1 ], c3step[ m ] );
}
printf( "\n" );
}
}
注:インデントに全角空白を用いています。コピペ後、タブに一括変換して下さい。
補足
入力された数値をそのまま英語に直すだけです。 出力例 num: 123 English: one hundred twenty-three num: 34445 English: thirty-four thousand four hundred forty-five num: 432143213 English: four hundred thirty-two million one hundred forty-three thousand two hundred thirteen. num: 999432143100 English: nine hundred ninty-nine billion four hundred thirty-two million one hundred forty-three thousand one hundred.