The code is:

string plaintext = GetString();
    for (int i = 0, n = strlen(plaintext); i < n; i++)
    printf("%c", plaintext[i]);
        if ((isalpha(plaintext[i])) && (isupper(plaintext[i])))
            int letter = 'plaintext[i]' ;
            int ciphertext = (letter + key) ;

And I get the errors "multi-character character constant" and "character constant too long for its type" for the line

int letter = 'plaintext[i]' ;

What do these mean and how do I fix them?


Simple fix. Look at the line:

int letter = 'plaintext[i]' ;

You are trying to put the integer (ASCII) value of a letter stored at plaintext[i] into the variable letter. The idea is right, but look at what you did. int letter = 'something' ; When you use the single quotes around something, it has to be a single character. If you had used double quotes, it would have had to be a string. So, because you used single quotes, the compiler is treating whatever is between them literally, ( usually described as a literal ) and anything longer than one character is too long.

Fix? drop the single quotes.

int letter = plaintext[i] ;

The compiler will now treat plaintext[i] as the array element that you intended to use.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .