This is in C language. When I call rotate() in main, the function returns false for isalpha() even though the string entered for plaintext uses alphabetic characters. Perhaps it’s identifying an alphabetic character by its ASCII value (‘A’ = 65)? I tried to test that out and used (char) with the letter variable in rotate() but it didn’t change anything.

PORTION OF MAIN

string plaintext = get_string("plaintext:  ");

    int length = strlen(plaintext);
    char ciphertext[length];

    for (int i = 0; i < length; i++)
    {
        ciphertext[i] = rotate(plaintext[i], key);
    }

ROTATE FUNCTION

char rotate(char letter, int key)
{
    if (isalpha(letter) == true)
    { ...
  • milon@lemm.eeOP
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    1 year ago

    Ah ha! Yes, I did check the docs but I think I just glanced over that portion. Be more careful next time. Now that I took another look at the other ctype.h functions, they all return 1 or 0. I think I confused equivalent python built-in functions as those evaluated to true/false. The < is a less than sign but it seems it doesn’t render correctly on Lemmy.