When I call rotate() in main, the function returns false for isalpha() when 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) { ...
jjagaimo@lemmy.ca 11 months ago
isalpha
documentation:You should be either checking for not equal to 0 instead of true, as its not necessarily guaranteed to be
1
~=true
Also make sure that your loop condition is
<
and not<
For more information, make sure to check the documentation for the standard library functions
pHr34kY@lemmy.world 11 months ago
I would drop the “== true” entirely. C will evaluate any nonzero int as true in an “if” statement.
milon@lemm.ee 11 months ago
Good point!
milon@lemm.ee 11 months ago
Ah ha! Yes, I did check the docs but I think I just glanced over that portion. Be more careful next time. The < is a less than sign but it seems it doesn’t render correctly on Lemmy.
lolcatnip@reddthat.com 11 months ago
Never, ever write “== true” or “== false” unless it’s absolutely necessary.