#include
#include
#include
main()
{
char a;
char b;
printf("请按下空格进入原文转译密码,按下回车进入密码转译原文,按下ESC则退出\n");
a='\0';
a=getch();
if(a==32)
{
printf("此项功能为原文译为密码~请输入你需要转译的...\n");
scanf("%c",&b);
if(b>=65&&b<=90)
{
if(b>=87)
{
b=b-26;
}
b=b+4;
printf("%c\n",b);
}
if(b>=97&&b<=122)
{
if(b>=119)
{
b=b-26;
}
b=b+4;
printf("%c\n",b);
}
}
if(a==13)
{
printf("此项功能为密码译为原文~请输入你需要转译的密码...\n");
scanf("%c",&b);
if(b>=65&&b<=90)
{
if(b<=68)
{
b=b+26;
}
b=b-4;
printf("%c\n",b);
}
if(b>=97&&b<=122)
{
if(b<=100)
{
b=b+26;
}
b=b-4;
printf("%c\n",b);
}
}
if(a==27)
{
printf("结束流程...\n");
return 0;
}
printf("程序结束...\n");
}
#include
void main()
{
char ch;
while(1)
{
ch=getchar();
if((ch>='a'&&ch<='v')||(ch>='A'&&ch<='V'))
{
ch=ch+4;
printf("%c",ch);
continue;
}
if((ch>='w'&&ch<='z')||(ch>='W'&&ch<='Z'))
{
ch=ch-22;
printf("%c",ch);
continue;
}
printf("%c",ch);
}
}//单字符输入
#include
void main()
{
int i;
char ch[100];
while(1)
{for(i=0;i<100;i++)
{ch[i]=getchar();
if(ch[i]!='\n')
{if((ch[i]>='a'&&ch[i]<='v')||(ch[i]>='A'&&ch[i]<='V'))
{ch[i]=ch[i]+4;printf("%c",ch[i]);}
else if((ch[i]>='w'&&ch[i]<='z')||(ch[i]>='W'&&ch[i]<='Z'))
{ch[i]=ch[i]-22;printf("%c",ch[i]);}
else printf("%c",ch[i]);
}
}
}
}//字符串输入
这样改下试试:
if((ch=getchar()) =='\n')break;