为什么编译器完全忽略第一个 for 循环然后转到第二个循环?

Why does the compiler completely ignore the first for loop then goes to the 2nd loop?

我一直在尝试制作可以加密消息的东西。我的问题是我的想法行不通。我有两套不同的字母表 char lettr_set1[]char lettr_set2[]lettr_set1 是字母表的前半部分,而 lettr_set2 是后半部分。可以这么说,我想让用户输入加密代码。可以这么说,我希望这封信与另一组中的相应字母交换字母。就像如果字母“a”在用户输入中可用,则应将其交换为“n”,如果字母“b”在用户输入中可用,则应将其交换为“o”等。在这一切之前,需要用户提供“加密代码”。然后应该将这种加密添加到每个单独的字母中。

例如加密密码为2,用户输入的是字母“n”,那么字母“n”现在应该是c。

我得到的输出只是被添加到初始用户输入而不是交换的加密代码。

#include <stdio.h>
#include <cs50.h>
#include <string.h>


    int main (void)
    {
     char lettr_set1[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'};
     char lettr_set2[] = {'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
     
     int number = get_int("Encryption code: ");
     
     if (number > 9)
     {
         printf("Error: 1 \nThis number is too big and might result in some letters not being found.\n");
        return 1;
     }
     
     string s = get_string("Message to encrypt: ");
     printf("Output: ");
    
    
     int n = strlen(s);
     
     if (strlen(s) < 8)
        {
           printf(" Error: 2 \n Your message is too short so an encrypted message can't be generated. \n");
           return 2;  
        }
    
     for (int i = 0; i < 12; i++)
       {
           
        if (s[i] == lettr_set2[i])
        {
           printf("%c", s[i] - 13);
        }
    
        if (s[i] == lettr_set1[i])
        {
           printf("%c", s[i] + 13);
        }
       }
    
     for (int i = 0; i < n; i++)
       {
       
        printf("%c", s[i] + number);
     
       }
     
     printf("\n");
    
    }

您的 for 循环和决策树必须如下所示:

// encryption "number" defined before and initialized via input
int i = 0;

while s[i] { // terminates when '[=10=]' is reached
    int found = 0;

    for (int j = 0; j < 13; j++) {
        if (s[i] == lettr_set1[j]) {
            printf("%c", lettr_set2[(j + number) % 13]);
            found = 1;
            break;
        }
    }

    if (!found) {
        for (int j = 0; j < 13; j++) {
            if (s[i] == lettr_set2[j]) {
                printf("%c", lettr_set1[(j - number) % 13]);
                break;
            }
        }
    }

    i++;
}