📄 menuchoose.cpp
字号:
#include"Huffmanhead.h"
extern *w;
extern weight[MAX],WeightTemp[123];
extern char CodeTemp[MAX];
extern char ShuruName[MAX],ShuruStr[MAX],HC[MAX][MAX];
extern HuffmanTree HT[MAX];
int n,ITure=0;//ITure用于判断是否已经进行初始化,n用于存放字符数
void MenuChoose()
{
printf("\n");
printf("Menu=");
char choosechar;
w=weight;
choosechar=getchar();
printf("\n");
do{
switch(choosechar)
{
case 'i':
if(ITure==0)
{
fflush(stdin);//清除残留在内存中的回车符
n=ShuruString(ShuruStr)-1;
HuffmanTreeBulid(HT,w,n);
ITure=1;
HuffmanCoding(HT,CodeTemp,n);
PrintHuffmanCode(n);
fflush(stdin);//清除残留在内存中的回车符
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
}
else
{
printf("The coding is OK now,if you want to reset,please choose‘R’to reset!\n\n");
}
break;
case 'I':
if(ITure==0)
{
fflush(stdin);//清除残留在内存中的回车符
n=ShuruString(ShuruStr)-1;
HuffmanTreeBulid(HT,w,n);
ITure=1;
HuffmanCoding(HT,CodeTemp,n);
PrintHuffmanCode(n);
fflush(stdin);//清除残留在内存中的回车符
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
}
else
{
printf("The coding is OK now,if you want to reset,please choose‘R’to reset!\n\n");
}
break;
case 'c':
if(ITure==1)
{
fflush(stdin);//清除残留在内存中的回车符
printf("Please input the code which you want to coding:\n\n");
printf("NewShuruStr=");
gets(ShuruStr);
fflush(stdin);//清除残留在内存中的回车符
PrintHuffmanCode(n);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
}
else
{
printf("You havn't input the code to initialize the application!Please input initialize first:\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
fflush(stdin);//清除残留在内存中的回车符
MenuChoose();
}
break;
case 'C':
if(ITure==1)
{
fflush(stdin);//清除残留在内存中的回车符
printf("Please input the code which you want to coding:\n\n");
printf("NewShuruStr=");
gets(ShuruStr);
fflush(stdin);//清除残留在内存中的回车符
PrintHuffmanCode(n);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
}
else
{
printf("You havn't input the code to initialize the application!Please input initialize first:\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
fflush(stdin);//清除残留在内存中的回车符
MenuChoose();
}
break;
case 'd':
if(ITure==1)
{
fflush(stdin);//清除残留在内存中的回车符
DecryptCoding(ShuruName,HT,n);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
}
else
{
printf("You havn't input the coding to initialize the application!Please input initialize first:\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
fflush(stdin);//清除残留在内存中的回车符
MenuChoose();
}
break;
case 'D':
if(ITure==1)
{
fflush(stdin);//清除残留在内存中的回车符
DecryptCoding(ShuruName,HT,n);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
}
else
{
printf("You havn't input the coding to initialize the application!Please input initialize first:\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
fflush(stdin);//清除残留在内存中的回车符
MenuChoose();
}
break;
case 'r':
fflush(stdin);//清除残留在内存中的回车符
ITure=ResetAll();
printf("Reset ok now!\n\n");
break;
case 'R':
fflush(stdin);//清除残留在内存中的回车符
ITure=ResetAll();
printf("Reset ok now!\n\n");
break;
case 's':
fflush(stdin);//清除残留在内存中的回车符
printf("This application is designed by alphalwei,and the GuideTeacher is WangMingLi!\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
break;
case 'S':
fflush(stdin);//清除残留在内存中的回车符
printf("This application is designed by alphalwei,and the GuideTeacher is WangMingLi!\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
break;
case 'e':
exit(0);
break;
case 'E':
exit(0);
break;
default:
printf("You are input a wrong parameter,please choose again:\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
fflush(stdin);//清除残留在内存中的回车符
MenuChoose();
}
printf("Please choose again:\n");
fflush(stdin);
MenuChoose();
}while(choosechar!='e'&&choosechar!='E');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -