【小工具】《文字小工具》
1、头函数:
1 //Trans.h 2 #ifndef TRANS_H_INCLUDED 3 #define TRANS_H_INCLUDED 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <string.h> 8 9 void creat(char txt[]) 10 { 11 int f=1; 12 for(int i=0;i<strlen(txt);i++) 13 { 14 txt[i]+=f; 15 f=-f; 16 } 17 printf("生成的加密文字为:%s\n",txt); 18 } 19 void trans(char txt[]) 20 { 21 int f=-1; 22 for(int i=0;i<strlen(txt);i++) 23 { 24 txt[i]+=f; 25 f=-f; 26 } 27 printf("解密后文字为:%s\n",txt); 28 } 29 30 #endif // TRANS_H_INCLUDED
2、源代码:
//Trans.h #ifndef TRANS_H_INCLUDED #define TRANS_H_INCLUDED #include <stdio.h> #include <stdlib.h> #include <string.h> void creat(char txt[]) { for(int i=0;i<strlen(txt);i++) { txt[i]+=1; } printf("生成的加密文字为:%s\n",txt); } void trans(char txt[]) { for(int i=0;i<strlen(txt);i++) { txt[i]-=1; } printf("解密后文字为:%s\n",txt); } #endif // TRANS_H_INCLUDED //主函数部分: #include "Trans.h" void main() { char txt[1024]; int choice; printf("---------------欢迎使用译码机!---------------\n"); printf("****************************************************\n"); printf("生成加密文字请输入1 翻译加密文字泣请输入2\n"); printf("退出程序请输入0\n"); while(1) { printf("****************************************************\n"); printf("请输入您的选择:"); scanf("%d",&choice); fflush(stdin); switch(choice) { case 1: printf("请输入文字:"); gets(txt); creat(txt); break; case 2: printf("请输入加密文字:"); gets(txt); trans(txt); break; case 0: printf("退出成功!\n"); exit(0); default: printf("您的输入有误,请重新输入!\n"); } system("pause"); } }

浙公网安备 33010602011771号