I have tried using single quotes notation to store the ascii value of a char in an int, but only as a hard coded character. I can't get it to work as it loops through the chars in the string. I tried something like

string plaintext = GetString();
for (int i = 0, n = strlen(plaintext); i < n; i++)

    if (isalpha(plaintext[i]))
        if (isupper(plaintext[i]))
            char c = plaintext[i];
            int letter = 'c';
            int cypher = (letter + ............);

This apparently hardcodes the ascii value of lower case c into my equation. What's the proper syntax?


You can just go ahead and treat it as an integer. If, for example, plaintext="bar", plaintext[0]=b=98, and you can just perform operations with it, such as plaintext[0]+1, which will yield 99.

You must log in to answer this question.

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