나는 몇 주 동안이 문제를 꼼짝 않고 바라 보았다. 작동하지 않습니다. 그 정도는 알고 있지만 왜 또는 무엇이 잘못되었는지는 알 수 없습니다. 나는 개발자가 "오류 : 기대되는 표현"을 뱉어 냈다는 것을 알고있다. 강조 표시된 행에 관한 것이지만 실제로는 빙산의 일각에 불과하다. 누군가가이 모든 작은 조각을 고치는 법을 알고 있다면 나는 그것을 크게 감사하겠다 !!!!! 좋아Caesar Cipher in C
는 그래서 내가 < N을 변경하고> = 당신이 놀라운 도우미 제안하고 그것을 통해 실행하고 생성되지만이보기 흉한 오류가 발생 글리치 여전히처럼 :
:(encrypts "a" as "b" using 1 as key
\ expected output, not an exit code of 0
:(encrypts "barfoo" as "yxocll" using 23 as key
\ expected output, not an exit code of 0
:(encrypts "BARFOO" as "EDUIRR" using 3 as key
\ expected output, but not "E\nA\nU\nI\nR\nR\n"
:(encrypts "BaRFoo" as "FeVJss" using 4 as key
어떤 제안이?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cs50.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
//Get the key
if (argc != 2 || atoi(argv[1]) < 0)
{
printf("Usage: ./caesar k");
return 1;
}
int key = atoi(argv[1]);
string plaintext = GetString();
for (int i = 0, n = strlen(plaintext); i < n; i++)
{
if (plaintext[i] > 'A' && plaintext[i] <= 'Z')
{
plaintext[i] = (plaintext[i] - 'A' + key) % 26 + 'A';
}
}
for (int i = 0, n = strlen(plaintext); i < n; i++)
{
if (plaintext[i] >= 'A' && plaintext[i] >= 'Z')
{
plaintext[i] = (plaintext[i] - 'A' + key) % 26 + 'A';
}
else if (plaintext[i] >= 'a' && plaintext[i] < 'z')
{
plaintext[i] = (plaintext[i] - 'a' + key) % 26 + 'a';
}
else
{
printf("%c\n", plaintext[i]);
}
}
return 0;
}
아 감사합니다. 정말 도움을 주셔서 감사합니다! – user3349389
대답을 수락 하시겠습니까? :) – Hafthor