0
當我使用數字4-22時,輸出不可靠,我不知道爲什麼。幫助將不勝感激,我也想知道爲什麼這不起作用。誰能告訴我我的凱撒算法有什麼問題?
#include<cs50.h>
#include<stdio.h>
#include<string.h>
int main(void)
{
int shifts;
int enc;
printf("What is your message ");
string message = get_string();
printf("By how many letters do you want to shift?");
scanf("%d",&shifts);
for(int i=0;i<strlen(message);i++)
{
enc=((message[i] - 89)+shifts)%26;
printf("%c",enc + 89);
}
printf("\n");
}
數字'89'似乎是錯誤的。另外,您應該分開處理小寫和大寫。 – nglee
使用字符常量,而不是像'89'這樣的幻數, –
另外,代碼中有內存泄漏。 –