0
在CS50的第2周,我撞上了一堵牆。我的代碼應該提示用戶輸入明文,然後在下一行打印一個簡單的密碼。問題是,我的代碼不斷地爲用戶打印確切的輸入,而不是加擾。我的代碼如下。Simple Cypher Program Not Working(CS50)
注意:我的代碼中的錯誤可能在for循環中,在相應的printf函數內下降。
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main (int argc, string argv[]){
if (argc != 2){
printf("You must enter two arguments, the second being a single digit integer!\n");
return 1;
}
int key = atoi(argv[1]);
printf("What do you want to encrpyt?");
string s = get_string();
for(int i=0; i < strlen(s); i++){
if (isupper(s[i])==true){
printf("%c",((s[i] + key)));
}
if (islower(s[i])==true){
printf("%c",s[i] + key);
}
else {
printf("%c",s[i]);
}
}
}