0

My code compiles but does not cipher the input text. For example; if I enter

./caesar 2

ABCdef

the code should output BCDefg but it only outputs a new line. My code glitches out when I try to code paste it here so I made a PasteBin of it. Any help will be appreciated.

1

for(int i = 0; i == strlen(s); i++)

This says, as long as i is equal to the length of s, run the loop. So this loop will never run, since i is 0. I think you meant i < strlen(s); so that it will run as once for each letter.

But to be better, you should say:

for (int i = 0, n = strlen(s); i < n; i++)

That way, you calculate the length of the string once, and then use that value in your comparison.

7
  • Oh wow I'm stupid, thanks a bunch! Dec 30 '16 at 1:14
  • No problem. Please accept my answer too so that this is removed from the unanswered queue. :)
    – curiouskiwi
    Dec 30 '16 at 1:15
  • yeah, it didn't let me check your answer because of some sort of 'five minute limit'. Thanks. Dec 30 '16 at 1:25
  • Oh, good to know. Thanks!
    – curiouskiwi
    Dec 30 '16 at 1:26
  • Oh and do you see why it only prints in upper case? if not I can make another post on it, but I thought I might as well ask you first. Dec 30 '16 at 1:27

You must log in to answer this question.

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