There are other threads related to this error, but none have solved my problem. Thank you for taking the time to read this - any help is appreciated!
I am coding a cypher in which you are meant to receive plaintext via user input and encode the message using a "key" entered by the user as a command-line argument to create the cyphertext. Only letters within the plaintext should be "shifted" using the key, while numbers and punctuation remain unchanged.
As of now, I believe I have the correct equations and structure in place, but I have multiple instances of the following error:
error:
array subscript is of type 'char' [-Werror,-Wchar-subscripts]"
I have tried casting different areas of this code as (char) to see if this solves the problem, but as I have been unable to find a fitting solution online, I'm stuck on where to go from here.
To ensure I am not going against the policies of the CS50 course, I will only be copying the necessary section of code.
string text = get_string("plaintext: ");
// ci = (pi + k) % 26
for (char i = 0; i < strlen(text); i++)
{
if (isupper(text[i]))
{
printf("%c", ((((text[i] + k) - 'A') % 26) + 'A'));
}
else if (islower(text[i]))
{
printf("%c", ((((text[i] + k) - 'a') % 26) + 'a'));
}
else
printf("%c", text[i]);
printf("ciphertext: %s
", c);
}
question from:
https://stackoverflow.com/questions/66050873/array-subscript-is-of-type-char-werror-wchar-subscripts-c-coding-a-cyp 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…