0

For some reason my program seems to be.. half-working? I have gone over my code over and over and I honestly can't figure out what I am doing wrong. Hopefully someone here can..

This is a snippet from my program where most of the encrypting is done. I did not paste the previous for loop, where I subtract 'A' from all capitals and 'a' from all lowercase because I wouldn't think that is the problem.

Here is a small example of my programming outputting incorrectly: http://i.gyazo.com/8aec044760afe32f34735ede3e79a9ba.png

Edit: Found the fix, see comments

for(int i = 0, counter = 0; i < slength; i++)
        {
            // If alphanumeric
            if(!isalpha(s[i]))
            {
                printf("%c", s[i]);
            }
            else 
            {
                // If uppercase && Alpha
                if(s[i] >= 'A' && s[i] <= 'Z')
                {
                    if(s[i] + j[counter] > 'Z')
                    {
                        char a = (s[i] + j[counter]) - 26;
                        printf("%c",a);
                    }
                    else
                    {
                        printf("%c", s[i] + j[counter]);
                        counter++;
                    }
                    if(slength == counter)
                    {
                        counter = 0;
                    }
                }
                if(s[i] >= 'a' && s[i] <= 'z')
                {
                    if(s[i] + j[counter] > 'z')
                    {
                        char a = (s[i] + j[counter]) - 26;
                        printf("%c",a);
                    }
                    else
                    {
                        printf("%c", s[i] + j[counter]);
                        counter++;
                    }
                    if(slength == counter)
                    {
                            counter = 0;
                    }

                }
            }

        }    
0
0

FOUND THE ERROR - Will keep post as a lesson to others..

I had counter++ in my else statements, when they obviously needed to be outside!

You must log in to answer this question.

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