0

here's the code (only look if you've completed this section!): http://pastebin.com/xNV5VJAw I was able to pretty quickly write a program the moves characters by k spaces, but I can't get it to wrap around once it gets past z or Z. You can see in this code I tried, but it has trouble once it gets to line 41 (once line 41 works, I can change line 45 to just print that character). Also, unrelated. How do I set it so that if there is no argc[2], the program returns 0? If I add argc =! 2, it still returns a segmentation fault if you type nothing after ./ceaser :(

4
  • Quick sanity checks.. As far as possible keep variables as local as possible. For eg. the "i" can be declared at line 38 inside the for loop instead of line 22. The curly brackets are missing in your for loop. Do you think your while loops are better replaced with for loops? Also can you elaborate your calculation at line 41? – ABor May 11 '16 at 17:10
  • 1. I see why moving the int i into the for loop works, thanks. 2. should the curly brackets go before the while loop? I would want it to check while every time it goes to the next letter in scramble (and im going to add an extra while for uppercase later). 3. why would i replace my while loop with a for loop? im not sure how i would even do that. 5. yes, my calculation there is a little off. consider this instead: (((scramble[i] - 65) + k) %26) +64) the idea being I index the ascii letters at 0 and dont let them go above 26 (with %26). then i add 65 after my key and string are combined & print – fishboy728 May 11 '16 at 17:39
  • There was a typo in my previous comment, I wanted to ask you if you can replace while loop with an if loop and not for. Sorry for that. Regarding the curly braces, decide what all is required to be done for one iteration of i (for eg. for one value of i you may need to do your calculation and then print the values etc.) All those activities needs to be within the fold of those curly brackets. Did you try your code with this new formula? What did you get? – ABor May 12 '16 at 3:31
  • i figured it out last night, thanks for the help! here's the code: pastebin.com/cQCci6r8 – fishboy728 May 12 '16 at 16:23

You must log in to answer this question.

Browse other questions tagged .