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]={'