0
다음 질문이 있습니다. 나는 그것을 암호화하기 위해 사용자 입력과 사용자 캐서 사이퍼를 읽을 필요가있다. 그러나 사용자 입력을 읽는 동안 다음과 같은 문제가 생겼습니다. 예를 들어 "./caesar 3 저는" 입니다. 문제가 문자 인 것 같습니다. ' 이 프로그램은 다른 입력에도 사용할 수 있습니다.C : " '"을 포함한 사용자 입력 문자열 - 문자
/**
*
* caesar.c
*
* The program caesar encrypts a String entered by the user
* using the caesar cipher technique. The user has to enter
* a key as additional command line argument. After that the
* user is asked to enter the String he wants to be encrypted.
*
* Usage: ./caesar key [char]
*
*/
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int caesarCipher(char original, int key);
int main(int argc, string argv[])
{
if (argc > 1)
{
int key = atoi(argv[1]);
for (int i = 2; i < argc; i++)
{
for (int j = 0; j < strlen(argv[i]); j++)
{
argv[i][j] = caesarCipher(argv[i][j], key);
}
}
for (int i = 2; i < argc; i++)
{
printf("%s", argv[i]);
}
return 0;
}
else
{
printf("The number of command arguments is wrong! \n");
return 1;
}
}
int caesarCipher(char original, int key)
{
char result = original;
if (islower(original))
{
result = (original - 97 + key) % 26 + 97;
}
else if (isupper(original))
{
result = (original - 65 + key) % 26 + 65;
}
return result;
}
감사합니다. – siebenschlaefer