0
{
        int j = 0;
        int k = strlen(key);

        code = toupper(key[j % k]) - 65;
        text = GetString();

        for (int i = 0; i < strlen(text); i++)
        {
            if (isalpha (text[i]))
            {
                if (isupper (text[i]))
                {
                    int x = (((text[i] - 65) + code) % 26 + 65);
                    printf("%c", x);
                }
                if (islower (text[i]))
                {
                    int y = (((text[i] - 97) + code) % 26 + 97);
                    printf("%c", y);
                }
                j++;

            }
            else
            {
                printf("%c", text[i]);
            }
1
  • Okay. I added: printf("\n"); just before return 0; and all errors but :world, say hello!..." went away. Aug 25, 2016 at 5:53

1 Answer 1

0

Hmmm, since there's no code to look at, let me get out my crystal ball and see if it's working. ;-)

I see that you're using the same index for the plain text as for the key, so the key indexes even when a non-alpha character is processed but nothing is encoded. I also predict that there's no line feed at the end of the run.

How's that? If not, then you need to post some code while I have the crystal ball repaired again. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

9
  • New to this, didn't know if I it was acceptable to post all my code. Aug 25, 2016 at 5:54
  • Because of the nature of this particular forum, it's a judgement call. If you're concerned, you can always remove it after the question is answered.
    – Cliff B
    Aug 25, 2016 at 5:55
  • Just saw that the word "say" is converted to "szz" not "rby". I need sleep! Aug 25, 2016 at 6:04
  • that would be your index problem. ;-)
    – Cliff B
    Aug 25, 2016 at 6:34
  • I have been working on the key indexing for 3 days now, and I still can't figure it out. My code just keeps getting worse and worse. Should I scrap everything and start over? Is there something fundamentally wrong with the entire code? I have been working under the assumption that if I get one part of my code working properly, then I can move on to the next part that isn't working. Aug 29, 2016 at 3:59

You must log in to answer this question.

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