0

This question has been asked before, but I believe I'm following the hints I've read about and my code is still not working. Below is a little bit of my code. I'm guessing the problem lies somewhere in here, but I can't figure out where. According to my pseudocode I had written down, this should work. Originally, I used a nested loop for my characters in my index but found this for loop from @Kareem who had explained it this way and it made it easier for me. But after that, I'm saying if it's an alphabetical character, then you have two options. If you're lowercase, cipher according to lowercase shifts, else do a different cipher if uppercase. If you're NOT alphabetical, I put an ELSE statement at the bottom still within the for loop, to indicate that if it's a blank space, comma, exclamation point, etc., that I would like for the computer to just print out that character and to not cipher it.

 for (int i = 0, n = strlen(p),m = strlen(argv[1]); i < n; i++)
 {
            //if alphabetical
            {
                    Lower case plaintext
                    {
                        //do something
                    }
                    Upper case plaintext
                    {
                        //do something
                    }
           }
           else     
           {
               //print character without ciphering;
           }
  }

Below is a picture of two tests. The first test is when I use spaces. As you can see, my cipher does not work and messes up at the first space and then on. When I tried my code without any spaces, it ciphers every letter correctly. I don't see why my ELSE statement of printf(%c, p[i]); is not doing what I intended for it to do. Appreciate any help!

terminal picture

1

you don't want to use i to keep track of the current key in the key string because i increases in every iteration regardless of whether the current character in the plain text is alphabetical or not.

1
  • Wow, I had a long ways to go. I finally got it though. Thanks again for your help. Pretty soon @Kareem will start charging me tutor fees... – Jzag May 31 '15 at 20:55

You must log in to answer this question.

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