比較簡單的
// 詞典.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <winbase.h>
#include <process.h>
void Search()
{
char temp[100];
char buffer[2];
char result[100];
printf("請輸入要查詢的單詞:\n");
scanf("%s",&temp);
buffer[0]=temp[0];
buffer[1]='\0';
int ret=GetPrivateProfileString(buffer,temp,0,result,100,"./date.ini");
if(ret>0)
printf("%s\n\n\n\n\n",result);
else
printf("對不起,沒有您要查找的單詞.\n\n\n\n\n");
}
void InsertItem()
{
char temp[100];
char buffer[2];
char result[100];
printf("請輸入要插入的單詞:\n");
scanf("%s",&temp);
printf("請輸入單詞的解釋:\n");
getchar();
scanf("%s",&result);
buffer[0]=temp[0];
buffer[1]='\0';
int ret=WritePrivateProfileString(buffer,temp,result,"./date.ini");
if(ret=0)
printf("插入失敗。\n\n\n\n\n");
else
printf("插入成功。\n\n\n\n\n");
}
int main(int argc, char* argv[])
{
int index;
main:
printf("**************MENU***************\n\n");
printf(" 1 英譯漢\n");
// printf("2 漢譯英\n");
printf(" 2 插入新的詞條\n");
// printf(" 3 刪除已有詞條\n");
printf(" 3 清空屏幕\n");
printf(" 4 退出\n\n");
printf("**********************************\n");
do{
printf("請選擇操作(1~4):\n");
scanf("%d",&index); /*輸入選擇項*/
}while(index<0||index>5); /*選擇項不在0~4之間重輸*/
switch(index)
{
case 1:
Search();
goto main;
break;
case 2:
InsertItem();
goto main;
break;
case 3:
system("cls");
goto main;
break;
case 4:
return 0;
break;
default:
break;
}
return 0;
}
輸出:
**************MENU***************
1 英譯漢
2 插入新的詞條
3 清空屏幕
4 退出
**********************************
請選擇操作(1~4):
1
請輸入要查詢的單詞:
bad
adj. 劣質的,有害的,壞的,不利的,不健康的,嚴重的
**************MENU***************
1 英譯漢
2 插入新的詞條
3 清空屏幕
4 退出
**********************************
請選擇操作(1~4):
2
請輸入要插入的單詞:
cat
請輸入單詞的解釋:
貓
插入成功。
**************MENU***************
1 英譯漢
2 插入新的詞條
3 清空屏幕
4 退出
**********************************
請選擇操作(1~4):
1
請輸入要查詢的單詞:
cat
貓
**************MENU***************
1 英譯漢
2 插入新的詞條
3 清空屏幕
4 退出
**********************************
請選擇操作(1~4):
4
Press any key to continue