0

I kind of know what to do... just having a hard time getting my head around it! This is my thinking: once I have asked the user for some text to cipher, I need to check if the text is indeed alphabet, uppercase and lowercase. I then need to get the ASCII value of the text, then change it to the alphabetical index (1-26), apply the key, then translate back to ASCII Here's the code, which I know is missing stuff. I'm sort of stuck. Any help to get me back on the road...

for(int i = 0, n = strlen(text); i < n; i++)
{

    if(isalpha(text[i])) //checks if text is indeed letters
    {
        if islower(text[i])
        {
            printf("%c", text[i]);
        }

        if isupper(text[i])
        {
            printf("%c", text[i]);
        }
0

You're on the right track. First, you need to accept an integer k, which you will add to the ASCII value of each letter in text. (BTW besides checking for case, your code needs to output non-alphabetical characters as is, your code cuts out so I don't know what your else condition is.) As per the pset specs, you can use the modulo operator % so that you loop around the alphabet ASCII values. Incidentally, you want to declare a new array which you will populate with your enciphered text, rather than printing out each character individually.

You must log in to answer this question.

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