0

The first line under

// Return

when uncommented prints funny chars sometimes ... always when the message to encrypt is one char long.

But when looped through as in the block two lines below // Return there's no funnyness.

I'm sure it's some sort of memory issue. I would like to know:

  1. What's the issues at hand here? Why is this happening?

  2. Which lines/blocks/fns in my code is causing them?

  3. What is a workaround so the line after // Return will work?

>

[code hidden]

3
  • If you're printing out "funny chars" it's almost certainly a problem with how the letters are being encoded. The code for that is in caesarEnc(), which you didn't post. Also, was x initialized at 0 or -1? If 0, then you're probably going to be out of synch by 1 on your key. Can you please post the missing code?
    – Cliff B
    Feb 9 '16 at 20:51
  • @CliffB - Missing code posted under Edit - 1 above. Yes, x was init'd at -1. My guess is that is some memory error. I say this cuz the 'funny chars' are not consistent. Note that the 'funny chars' only appear with printf (of enc_mess), not when iterating over it.
    – dirkdirk
    Feb 9 '16 at 21:19
  • Iteration over enc_mess solves the problem, but I want to know what's going on under the hood with printf.
    – dirkdirk
    Feb 9 '16 at 21:27
0

This is a case where finding the problem depends on seeing all of the code. I took the code posted to date and built the rest of the program around it, and it passed check50 except for the test for a key with a number. (I didn't code that.) So, if you are still having problems, the issue lies elsewhere.

You should run your code in the debugger and monitor all of the vars to see what's not being set correctly or where your program is going off into the weeds.

3
  • Cliff - thanks for the help so far. I'm under the impression we're not supposed to post complete solutions to any problem. I'm more than happy to post all my code, but don't want to violate academic honesty.
    – dirkdirk
    Feb 9 '16 at 22:26
  • Actually, the amount of code you posted is too much and I've edited it away (still accessible behind the edits link.)
    – curiouskiwi
    Feb 10 '16 at 6:54
  • @curiouskiwi - No worries mate. I was concerned I was posting too much. So what's the best way to go about getting my question re full code answered. BTW I'm taking the online course and am not on campus.
    – dirkdirk
    Feb 10 '16 at 17:03
-1

You forgot to declare or initialize variable x.

2
  • I left off the top part of the script where many vars are declared and initialized. The fn caesarEnc isn't there either. Regardless, not declaring x wouldn't cause the error I describe anyway.
    – dirkdirk
    Feb 9 '16 at 15:35
  • Why the downvote? You left out that part so we're left guessing as to the source of the error. You're right, it wouldn't have led to the error you're seeing (in fact it wouldn't have compiled) but no other error was apparent in the snippet you posted.
    – ronga
    Feb 10 '16 at 1:10

You must log in to answer this question.

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