demo/number_to_pinyin.c
2019-11-03 19:32:38 +08:00

32 lines
568 B
C

#include <stdio.h>
char *map[] = {
"ling", "yi", "er", "san", "si",
"wu", "liu", "qi", "ba", "jiu"
};
void display_num_with_pinyin(int num)
{
char *stack[10] = {0,};
int stack_top = 0;
char *sign = "";
if (num < 0) {
sign = "fu ";
num = -num;
}
for (; num; num = num / 10) {
stack[stack_top++] = map[num % 10];
}
printf("%s", sign);
while (--stack_top > -1) {
printf("%s ", stack[stack_top]);
}
printf("\b\n");
}
int main()
{
display_num_with_pinyin(-6543210);
return 0;
}