2. Counting in Lojban, an artificial language developed
over the last fourty years, is easier than in most languages
The numbers from zero to nine are:
0 no
1 pa
2 re
3 ci
4 vo
5 mk
6 xa
7 ze
8 bi
9 so
Larger numbers are created by gluing the digit togather.
For Examle 123 is pareci
Write a program that reads in a lojban string(representing
a no less than or equal to 1,000,000) and output it in
numbers.

Answer Posted / abdur rab

#include <stdio.h>

int decimal_from_logban ( char* cp_logban )
{
if ( !strcmp ( cp_logban, "no" ) ) return 0;
if ( !strcmp ( cp_logban, "pa" ) ) return 1;
if ( !strcmp ( cp_logban, "re" ) ) return 2;
if ( !strcmp ( cp_logban, "ci" ) ) return 3;
if ( !strcmp ( cp_logban, "vo" ) ) return 4;
if ( !strcmp ( cp_logban, "mk" ) ) return 5;
if ( !strcmp ( cp_logban, "xa" ) ) return 6;
if ( !strcmp ( cp_logban, "ze" ) ) return 7;
if ( !strcmp ( cp_logban, "bi" ) ) return 8;
if ( !strcmp ( cp_logban, "so" ) ) return 9;
}

void logban_2_decimal ( char* _lojban, int* _decimal )
{
char lojban_array [3];

memset ( lojban_array, '\0', 3 );
if ( ( NULL != _lojban ) && ( '\0' != *( _lojban +
2 ) ) ) {
logban_2_decimal ( _lojban + 2, _decimal +
1 );
strncpy ( lojban_array, _lojban, 2 );
*_decimal = decimal_from_logban (
lojban_array );
} else {
strncpy ( lojban_array, _lojban, 2 );
*_decimal = decimal_from_logban (
lojban_array );
}

}

int main ( int argc, char* argv [] )
{
char number_lojban [] = {"sopareci"};
int number_decimal [8];
int i = 0;

logban_2_decimal ( number_lojban, number_decimal ) ;
printf ( "\nLojban :%s", number_lojban );

printf ( "\nDecimal :" );
for ( i = 0; i < ( strlen ( number_lojban ) / 2 );
i++ )
printf ("%d", number_decimal [ i ] );

return ( 0 );
}

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

1719


How can I find out the size of a file, prior to reading it in?

632


What is difference between array and structure in c?

585


What is pass by reference in c?

619


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

666






Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

1872


What is #include stdio h?

691


What are local variables c?

556


What is omp_num_threads?

587


What is logical error?

610


What do the functions atoi(), itoa() and gcvt() do?

730


Why flag is used in c?

659


How can I call a function with an argument list built up at run time?

648


what are enumerations in C

731


What is a newline escape sequence?

673