當前位置:首頁 » 編程語言 » 翻譯c語言代碼

翻譯c語言代碼

發布時間: 2024-07-10 18:08:08

① C語言編程源代碼翻譯

#include<stdio.h>//頭文件
intmain(void)//主函數
{
intdogs;//定義整型變數dogs
printf("Howmanydogsdoyouhave? ");//屏幕上輸出:Howmanydogsdoyouhave?
scanf("%d",&dogs);//從鍵盤輸入一個數,這個數給dogs賦值,之後dogs的值就是這個數
printf("soyouhave%ddog(s)! ",dogs);//屏幕上輸出:soyouhave(你從鍵盤輸入的那個數)dog(s)!
return0;
}
}

② 如何用C語言來製作翻譯器

寫了一個簡單的翻譯器,只提供單詞翻譯,中文到英文,英文到中文都行,你需要首先進行字典錄入。錄入以後會自動在目錄下生成一個dic.txt文件。
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
#define
filename
"dic.txt"
struct
word
//字典結構體
{
char
chinese[20];
//中文
char
english[20];
//英文
};
/////////////////////////////////////////////////////////////
file
*fp;
//全局文件指針
file
*
fileopen(char
filename[])
//文件打開函數
{
file
*fp;
if((fp=fopen(filename,"r"))==null)
{
fp=fopen(filename,"w");
cout<<"文件打開失敗重新創建記錄文件";
return
fp;
}
fp=fopen(filename,"a+");
return
fp;
}
void
fileclose(file
*fp)
//文件關閉函數
{
if(fclose(fp)==0)
cout<<"安全關閉"<<endl;
else
cout<<"文件關閉失敗"<<endl;
}
////////////////////////////////////////////////////////////////
void
tra1()
//中文翻譯成英文模塊
{
file
*fp;
if((fp=fopen(filename,"r"))==null)
{
printf("文件打開失敗!");
}
char
tempchinese[20];
word
temp;
printf("請輸入中文單詞:");
scanf("%s",tempchinese);
while(fread(&temp,sizeof(word),1,fp)==1)
{
if(strcmp(temp.chinese,tempchinese)==0)
{
printf("中文:%s
英文:%s
\n",temp.chinese,temp.english);
}
}
printf("查找完畢!");
fileclose(fp);
}
//////////////////////////////////////////////
void
tra2()
//英文翻譯成中文模塊
{
file
*fp;
if((fp=fopen(filename,"r"))==null)
{
printf("文件打開失敗!");
}
char
tempenglish[20];
word
temp;
printf("請輸入英文單詞:");
scanf("%s",tempenglish);
while(fread(&temp,sizeof(word),1,fp)==1)
{
if(strcmp(temp.english,tempenglish)==0)
{
printf("中文:%s
英文:%s
\n",temp.chinese,temp.english);
}
}
printf("查找完畢!");
fileclose(fp);
}
////////////////////////////////////////////////
void
inp()
//字典錄入模塊
{
fp=fileopen(filename);
word
temp;
printf("請輸入英文:");
scanf("%s",temp.english);
printf("請輸入對應中文:");
scanf("%s",temp.chinese);
fwrite(&temp,sizeof(temp),1,fp);
printf("信息添加完成");
fileclose(fp);
}
////////////////////////////////////////////////
int
menu()
//主目錄模塊
{
int
choose;
while(choose!=0)
{
printf("\n");
printf("簡易中英翻譯系統\n");
printf("1、中->英翻譯\n");
printf("2、英-中翻譯\n");
printf("3、字典錄入\n");
printf("輸入0退出系統\n");
printf("請輸入:");
scanf("%d",&choose);
switch(choose)
{
case
0:return
0;break;
case
1:tra1();break;
case
2:tra2();break;
case
3:inp();break;
}
}
}
///////////////////////////////////////////////////////
void
main()
{
menu();
}

③ 鎬ユ眰錛侊紒c璇璦錛岀炕璇戜互涓嬩唬鐮佸悇琛屼粈涔堟剰鎬濓紝璋㈣阿浜

銆int mylogin()
銆銆{
銆銆int i,j,鍏抽敭,count = 0;
銆銆char瀵嗙爜[20];
銆銆printf(鈥滆瘋緭鍏ュ瘑鐮:鈥);
銆銆鍋
銆銆{
銆銆(鎴= 0;i < 20;鎴+ +)
銆銆{
銆銆瀵嗙爜[鎴慮= getch();
銆銆濡傛灉(瀵嗙爜[鎴慮= = ' \ b ')/ *閫鏍* /
銆銆{
銆銆緋葷粺(鈥渃ls鈥);娓呭睆/ * * /
銆銆printf(鈥滆瘋緭鍏ュ瘑鐮:鈥);
銆銆瀵逛簬(j = 0;j <鎴2;j + +)
銆銆{
銆銆printf(鈥*鈥);
銆銆}
銆銆鎴=鎴2;
銆銆}
銆銆濡傛灉(瀵嗙爜[鎴慮= = ' \ x0d)/ *鍥炶濺鍒欑粓姝㈠驚鐜* /
銆銆{
銆銆瀵嗙爜[鎴慮= ' \ 0 ';/ *瀛椾覆絎︾粨灝炬爣蹇* /
銆銆鎵撶牬;
銆銆}
銆銆鍒鐨
銆銆{
銆銆printf(鈥*鈥);
銆銆}
銆銆}
銆銆printf(" \ n " int mylogin() //榪斿洖鍊間負鏁存暟鐨刴ylogin鍑芥暟
{
int i,j,key,count=0; //澹版槑騫跺畾涔4涓鏁村瀷鍙橀噺錛屽叾涓璫ount鐨勫垵鍊間負0
char password[20]; //澹版槑騫跺畾涔変竴涓瀹歸噺涓20鐨勫瓧絎︽暟緇
printf("Please enter the password錛"); //CMD紿楀彛杈撳嚭錛歅lease enter the password錛
do //do while 璇鍙ワ紝鍏堟墽琛屽悗鍒ゆ柇錛屾潯浠朵笉鎴愮珛錛岀粨鏉
{
for (i=0; i<20; i++) //for寰鐜錛宨鍒濆0錛屽傛灉灝忎簬20錛屾墽琛屾嫭鍙烽噷鐨勮鍙ワ紝鑷鍔1錛屽啀鍜20姣旇緝錛屾垚絝嬬戶緇鎵ц屾嫭鍙烽噷璇鍙ワ紝鐩村埌i澶т簬絳変簬20
{
password[i] = getch(); //緇欏瓧絎︽暟緇勮緭鍏ヤ竴涓瀛楃︼紝getch鍙栧緱浣犺緭鍏ョ殑瀛楃﹀苟榪斿洖緇欎粬
if(password[i]=='\b')/*閫鏍*/ //褰撲綘杈撳叆閫鏍肩殑鏃跺
{
system("cls");/*娓呭睆*/ //浠栧凡緇忚翠簡
printf("Please enter the password錛"); //鍚屼笂闈㈢殑printf
for(j=0;j<i-2;j++) //鍚屼笂闈for
{
printf("*"); //.....榪樻槸閭f牱

i=i-2; //鎶奿-2鐨勫煎嶅埗緇檌

if (password[i] == '\x0d')/*鍥炶濺鍒欑粓姝㈠驚鐜*/
{
password[i]='\0';/*瀛楃︿覆緇撳熬鏍囧織*/
break; //鍒囧嚭寰鐜
}
else if鏉′歡涓嶆弧瓚籌紝鍒欐墽琛岃繖鍙
{
printf("*");
}
}
printf("\n"); //杈撳嚭鍥炶濺
key=login(password,20); //璋冪敤鍑芥暟鑷韜錛屽苟浠栫殑榪斿洖鍊肩粰key
if(key==1) //濡傛灉key絳変簬1錛屽垏鍑哄驚鐜
{
break;
}
else 鍚﹀垯杈撳叆瀵嗙爜閿欒錛堝洖杞︼級璇烽噸鏂拌緭鍏ワ細
{
printf("瀵嗙爜閿欒!\n璇烽噸鏂拌緭鍏ワ細");
}
count++; cout鑷鍔
}while(count<3); 濡傛灉cout<3錛屾墽琛屼笂闈㈢殑do璇鍙
return key; 榪斿洖key鐨勫肩粰鍑芥暟

熱點內容
去哪裡找自己的支付密碼 發布:2024-10-25 14:46:18 瀏覽:417
生產文件夾 發布:2024-10-25 14:46:14 瀏覽:705
windows搭建ftp伺服器埠修改 發布:2024-10-25 14:46:11 瀏覽:322
勞拉與馬ftp 發布:2024-10-25 00:21:16 瀏覽:359
奪寶網站源碼 發布:2024-10-25 00:19:02 瀏覽:454
編程文本編輯器 發布:2024-10-25 00:09:28 瀏覽:972
編程徐帥 發布:2024-10-25 00:03:25 瀏覽:307
手機安卓模擬器如何打開文件 發布:2024-10-25 00:02:55 瀏覽:722
pythonday 發布:2024-10-24 23:55:47 瀏覽:425
g編譯c文件 發布:2024-10-24 23:55:03 瀏覽:294