#包含?& ltstdio.h & gt
#包含?& ltstring.h & gt
#定義?麥克斯。100
int?isValidate(char?str[]);
int?isLetter(char?ch);
int?isLow(char?ch);
作廢?加密(char?來源[],?夏爾?dest[]);
作廢?主()
{
夏爾?source[MAX];
夏爾?dest[MAX];
printf("輸入?答?字符串?:?");
獲取(源);
if(isValidate(source)?==?0)
{
printf(" error \ n ");
返回;
}
if(strlen(來源)?& gt?20)
{
來源[20]?=?'\0';
}
加密(來源,dest);
printf("加密?:?%s\n ",dest);
}
/*?判斷字符串str是否合法?*/
int?isValidate(char?str[])
{
int?我,?len
萊恩。=?strlen(str);
如果(len?& lt=?0)
{
回歸?0;
}
for(I = 0;?我& ltlen?i++)
{
if(isLetter(str[i])?==?0)
{
回歸?0;
}
}
回歸?1;
}
/*?判斷字符ch是不是字母?*/
int?isLetter(char?ch)
{
如果((ch?& gt=?壹個嗎?& amp& amp?ch?& lt=?z’)?||?(ch?& gt=?壹個嗎?& amp& amp?ch?& lt=?z '))
{
回歸?1;
}
其他
{
回歸?0;
}
}
/*?判斷字符ch是否小寫。*/
int?isLow(char?ch)
{
如果(ch?& gt=?壹個嗎?& amp& amp?ch?& lt=?z’)
{
回歸?1;
}
其他
{
回歸?0;
}
}
/*?加密字符串?*/
作廢?加密(char?來源[],?夏爾?目標[])
{
int?萊恩。=?strlen(來源);
for(int?I = 0;?我& ltlen?i++)
{
if(isLow(source[i])?==?1)
{
dest[i]?=?(來源[i]?-?壹個嗎?+?4)?%?26?+?a’;
}
其他
{
dest[i]?=?(來源[i]?-?壹個嗎?+?4)?%?26?+?a’;
}
}
dest[i]?=?'\0';
}運行測試:
輸入?答?字符串?:?中國
加密?:?Glmre