小编100*_*oon的帖子

我应该如何让用户输入我想要的信息?

我刚开始学习计算机科学。

我正在通过在哈佛在线教授的 CS50 学习。好吧,我正在解决这个问题,我需要在命令行中从用户那里获取密钥,然后是明文,然后将该文本转换为 ASCII 中的密钥数量以生成密文。

这是我到目前为止所得到的。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(int argc, string argv[])
{
    if (argc != 2)
    {
        printf("Usage: ./caesar key\n");
    }

    {
        string plaintext = get_string("plaintext:  ");

        int key = atoi(argv[1]);
        int n = strlen(plaintext);
        char chr[n];

        printf("ciphertext: ");
        for (int i = 0; i < n; i++)
        {
            chr[i] = plaintext[i];
            if (isalpha(chr[i]))
            {
                if (isupper(chr[i]))
                {
                    chr[i] = (chr[i] - 65 + key) % 26 + 65;
                    printf("%c",chr[i]);    
                } …
Run Code Online (Sandbox Code Playgroud)

c caesar-cipher cs50

1
推荐指数
1
解决办法
116
查看次数

标签 统计

c ×1

caesar-cipher ×1

cs50 ×1