C语言 汉字转拼音
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <windows.h> #define N 100 int cishu(char *a,char *b) { int n=0; while(*a) { if(*a==*b) n++; a++; } return n; } char * retpinyin() { static char name[10]; srand((unsigned)time(NULL)); int iRange1 = 0xf7 - 0xb0; int iRange2 = 0xfe - 0xa1; char iCode1 = rand()%iRange1 + 0xb0; char iCode2 = rand()%iRange2 + 0xa1; char chh[3] = {iCode1,iCode2,0}; strcpy(name,chh); return name; } int StrReplace(char strRes[],char from[], char to[]) { int i,flag = 0; char *p,*q,*ts; for(i = 0; strRes[i]; ++i) { if(strRes[i] == from[0]) { p = strRes + i; q = from; while(*q && (*p++ == *q++)); if(*q == '\0') { ts = (char *)malloc(strlen(strRes) + 1); strcpy(ts,p); strRes[i] = '\0'; strcat(strRes,to); strcat(strRes,ts); free(ts); flag = 1; } break; } } return flag; } int main() { int zongshu=0,zhengque=0,cuo=0; int zheng=0,bz=0; int a=0; FILE *fp; char str[N + 1],ch[2],ch1[20],ch2[20],chx[10],str1[N+1]; char * chh; char *p; //判断文件是否打开失败 if ( (fp = fopen("duizhao1.txt", "rt")) == NULL ) { puts("Fail to open file!"); exit(0); } while(1) { if(zongshu%5==0 && zongshu!=0) { system("cls"); if(zheng==2) { printf("%s\n",str,str1); } printf("共计做对=%d个,错误=%d\n",zhengque,cuo); } zheng=0; chh=retpinyin(); //chh="阿"; printf("%s\n",chh); scanf("%s",&chx); if(strcmp(chx,"1")==0) break; while( fgets(str, N, fp) != NULL ) { if(strstr(str,chh)!=0) { strcpy(str1,str); StrReplace(str1,chh,""); StrReplace(str1," ",""); StrReplace(str1,"\n",""); if(cishu(str1," ")>=1) { p = strtok(str1, " "); while(p) { if(strcmp(p,chx)==0) { bz++; } //printf("....kkk%s\n", p); p = strtok(NULL, " "); } if(bz>=1) { zheng=1; zhengque++; printf("对了!\n"); printf("共计做对=%d个,错误=%d\n",zhengque,cuo); } else { cuo++; printf("错了!\n"); printf("正确答案:%s\n",str1); printf("共计做对=%d个,错误=%d\n",zhengque,cuo); zheng=2; } } else { if(strcmp(str1,chx)==0) { zheng=1; zhengque++; printf("对了!\n"); printf("共计做对=%d个,错误=%d\n",zhengque,cuo); } else { cuo++; printf("错了!\n"); printf("正确答案:%s\n",str1); printf("共计做对=%d个,错误=%d\n",zhengque,cuo); zheng=2; } break;} break; } } if(zheng==0) { printf("对照表中没有%s\n",chh); zheng=0; } rewind(fp); // fp回到开始位置 zongshu++; } fclose(fp); return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了