I think you wanted to use single quotes (apostrophe) and not doubles. There is a big difference between them. single quotes indicate a single character and double quotes indicate a sequence of characters terminated by a null value. Although it has only one character, it is considered a valid string character and still has the terminator, and still needs to compare all characters in the string to indicate equality, but it doesn’t look like you want this, you just want to compare a character.
In addition this code neither compiles, at least in the presented form, then either presented a different one than what is using or is reporting a different error than what happens. There is an error in the construction of the Boolean expression within the if
mixing operands inappropriately, you can not use as in mathematics, can only compare two operands at a time in the operators.
I’m not judging logic because the question doesn’t make it so clear, there may be error there too.
I’m going to simplify some things and do it the right way in C.
char msg[1000];
printf("Escreva a mensagem para ser criptografada: ");
fgets(msg, sizeof(msg), stdin);
for (int i = msg; *i != '\0'; i++) *i = ((*i >= 'A' && *i <= 'Z') || (*i >= 'a' && *i <= 'z')) ? *i + 3 : *i;
I put in the Github for future reference.
There’s actually an obvious logic error there. If 3 letters are missing to finish the alphabet it should start again there at the beginning, then the letters Y, W and Z should turn into A, B or C. I let you hit this until to continue the exercise.
Behold: Whenever I am going to scan a string in C I must use "strlen()", right?.
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero