c加密字母
发布时间: 2023-01-21 20:57:39
#include<stdio.h>
#include<string.h>
intmain()
{
charstr[]="00000",str2[]="00000",*p=str,*p2=str2;
printf("输入5个字母:");
while(*p!=0)
{
scanf("%c",p);
if(*p=='
')
continue;
if(*p<'A'||(*p>'Z'&&*p<'a')||*p>'z')//输入验证,必须是字母
{
printf("只能输入字母,请重新输入
");
p=str;
p2=str2;
fflush(stdin);//输入有错重新输入前清空缓冲区。fflush属于c扩展函数,正常使用没问题,如需在linuxggc上使用,考虑多次调用getchar函数来清空
}
else
{
*p2=(*p)+4;
if(*p2>90&&*p2<97)//大写字母加4,最大位不超出
*p2='A'+(*p2-90)-1;
if(*p2>122)//小写字母加4,最大位不超出
*p2='a'+(*p2-122)-1;
p2++;
p++;
}
}
printf("原字符串为:%s
加密后的字符串为:%s
",str,str2);
return0;
}
② c语言字母加密
按照你的要求编写的字母加密的C语言程序如下
(姓字母向后移两位,名字母向后移三位)
#include<stdio.h>
#include<string.h>
int main(){
char src[30],result[]="",ch[2]={'