//这段程序错误太多,而且代码风格太乱;
//不过估计您是个初学者,就帮你的程序按你思路修改了
//运行结果如下:
模仿拼音输入法
请输入拼音wo
wo
0.挝 1.莴 2.涡 3.窝 4.蜗 5.倭 6.踒 7.喔 8.我 9.肟 10.沃 11.卧 12.偓 13.握 14.幄
15.渥 16.龌 17.涴 18.硪 19.斡 请输入对应的序号选字:2
涡
//修改后程序如下,希望对你有用!
#include<stdio.h>
#include<string.h>
int main() //是int还是void,根据编译器,我用的是CodeBlocks需要用int
{
char wo[]= {"wo"}
char wo_ch[]= {"挝莴涡窝蜗倭踒喔我肟沃卧偓握幄渥龌涴硪斡"}
printf("%d:%s\n", strlen(wo_ch), wo_ch)
//char str_input[3]
unsigned int i=0,str_ch_len=strlen(wo_ch)
printf("模仿拼音输入法\n")
printf("请输入拼音wo\n")
//scanf("%s",str_input)
char str_input[3]
gets(str_input)//输入拼音
//if(str_input==wo)//修改如下(字符串是不能直接比较的!)
if (0==strcmp(str_input,wo))
{
for(i=0 i<str_ch_len i+=2)
//printf("%d.%c "i,wo_ch[i]) //修改如下(双引号之后应该有,号)
printf("%d.%c%c ",i/2,wo_ch[i],wo_ch[i+1])
last:
printf("请输入对应的序号选字:")
//scanf("%d" &i) //修改如下
unsigned int n
scanf("%u", &n)
if (2*n>str_ch_len)
{
printf("你要选的字符不存在\n")
goto last
}
else
{
printf("%c%c",wo_ch[2*n],wo_ch[2*n+1])
}
}
else
{
printf("对不起,没有找到该拼音的字库\n")
}
return 0//如果主函数是void,删除此行!
}
定义变量什么的都可以使用拼音,但是最好不要这样做,因为这样不是良好的编码风格,如果你以后自己看自己的程序的时候,拼音会让你自己都不知道自己写的什么东西。最好还是用单词,如果单词比较多可以用单词的缩写#include <math.h>#include <stdio.h>
#include <string.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
char *numpinyin(char *buf, unsigned int n)
{
switch (n)
{
case 0: strcpy(buf, "líng") return buf break
case 1: strcpy(buf, "yī") return buf break
case 2: strcpy(buf, "èr") return buf break
case 3: strcpy(buf, "sān") return buf break
case 4: strcpy(buf, "sì") return buf break
case 5: strcpy(buf, "wǔ") return buf break
case 6: strcpy(buf, "liù") return buf break
case 7: strcpy(buf, "qī") return buf break
case 8: strcpy(buf, "bā") return buf break
case 9: strcpy(buf, "jiǔ") return buf break
case 10: strcpy(buf, "shí") return buf break
case 100: strcpy(buf, "bǎi") return buf break
default: return NULL break
}
}
int getdigit(unsigned int n, unsigned int d)
{
char str[4] = ""
if (n <= 999)
{
sprintf(str, "%03d", n)
return str[d] - 48
}
else
return -1
}
int power(int x, int y)
{
int result = 1, i = 0
for ( i < y i ++)
result *= x
return result
}
int main(void)
{
int n = 0, num = 0, count = 0, i = 0
char buffer[5] = ""
scanf("%d", &n)
for ( count < MIN(n, 20) count ++)
{
scanf("%d", &num)
if (num > 999)
printf("The number you typed is not a three-digit or smaller integer!\n")
else
{
if (num == 0)
{
numpinyin(buffer, num)
printf("%s\n", buffer)
}
else
{
for (i = 0 i < 3 i ++)
{
if (getdigit(num, i) > 0)
{
if (i == 2 && getdigit(num, 0) != 0 && getdigit(num, 1) == 0)
{
numpinyin(buffer, 0)
printf("%s ", buffer)
}
numpinyin(buffer, getdigit(num, i))
if (i < 2)
printf("%s ", buffer)
else
printf("%s", buffer)
if (i < 2)
{
numpinyin(buffer, power(10, 2 - i))
printf("%s ", buffer)
}
}
}
putchar('\n')
}
}
}
return 0
}
精心编写代码,实在不易,望采纳,谢谢。。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)