Я могу получить его для печати открытого текста и смещения по значению ключа, но Я немного смущен тем, как заставить письма обернуться и как реализовать его в моем код.Получение Caesar Cipher для обертывания
Любые предложения будут оценены.
спасибо.
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
//Gets number of user arguments and the key.
int main (int argc, string argv[]) {
if(argc != 2) {
printf("try again\n");
}
//Converts string to int.
int key = atoi(argv[1]);
//Will store the chars + key.
int result;
printf("Please enter what you would like to encrypt: ");
//Gets plaintext from user.
string plainText = get_string();
//Iterates over the user's input, checking for the case of each char.
for (int i = 0; i <= strlen(plainText); i++) {
if (toupper(plainText[i]) || tolower(plainText[i])) {
result = plainText[i];
}
//Checks if i'th char is a letter and shifts it.
if (isalpha(plainText[i])) {
result = plainText[i + key];
}
}
printf("%c", result);
}
Возможный дубликат [Домашнее задание (ревизия): шифр Цезаря, обернуть вокруг, когда char>> z (C++)] (http://stackoverflow.com/questions/8489474/homeworkrevision-caesar-cipher-wrap-around-when- chars-are-zc) – Ari0nhh
Что это должно делать: 'if (toupper (plainText [i]) || tolower (plainText [i]))'? –