-1
jharvard@appliance (~/Dropbox/pset2): check50 2014/x/pset2/caesar caesar.c
:) caesar.c exists
:) caesar.c compiles
:( encrypts "a" as "b" using 1 as key
   \ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 215..."
:( encrypts "barfoo" as "yxocll" using 23 as key
   \ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 215..."
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
   \ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 215..."
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
   \ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 215..."
:( encrypts "barfoo" as "onesbb" using 65 as key
   \ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 214..."
:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
   \ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 215..."
:) handles lack of argv[1]
https://sandbox.cs50.net/checks/2f449728b97446c58778fc95360f4897
jharvard@appliance (~/Dropbox/pset2): ./caesar 1
a
b
jharvard@appliance (~/Dropbox/pset2): ./caesar 3
BARFOO
EDUIRR
jharvard@appliance (~/Dropbox/pset2): 
4
  • Can you give us snippets of your code you think are causing the problem (everything around line 31, e.g.)?
    – pat_krat
    Commented Sep 4, 2014 at 7:19
  • My code does not have a line 31. Commented Sep 4, 2014 at 11:22
  • @Patrick The error message is pointing to line 31 of run.sh.
    – Air
    Commented Sep 4, 2014 at 19:16
  • @Nigel You're not allowed to dump your code here, and if you solve the problem, you should post an answer, not edit the question. It would be great if you could describe what you did to solve the problem in an answer, for the benefit of future readers - without showing them your full code for the problem set.
    – Air
    Commented Sep 4, 2014 at 19:18

2 Answers 2

0

Make sure that your check contains upper and lower cases. Check print, if you added "(argument)\n" , its possible to get wrong. If you have that remove \n and make you program to print new line at the end. You might wanna take some notes to: 1. What will happen if you don't have argv..You should exit the program or retry until argv is filled with positive number. 2. Does you program handles symbols like '\' or ' '.. you should print that symbols the same as the user type them.

I hope this will help you.

0

Change your initial condition to

if (argc != 2)

rather than if (argc == 1), because you want to return an error every time the user has not provided exactly 2 arguments.

No need to initialise "x = 0" outside your for loop, because you can do so within the initialisation of the loop. Don't forget to provide the data type though:

for(int x = 0; ...)

Make your for loop more efficient by letting it count strlen() only once:

for(int x = 0, y = strlen(plain); x < y; x++)

Regarding your nested loops, you should work on the following:

First, check whether plain[x] is a letter or not by using the isalpha() function.

Second, if isalpha() returns true, check whether plain[x] is uppercase or lowercase by using the isupper() and islower() functions. - Are either of these conditions met, you can include your code for encryption here.

Third, If isalpha() is not met, you do not want to encrypt anything, so include a statement such as

else
{
    printf("%c", plain[x]);
}

Finally, you don't need an if statement that breaks the loop if x >= strlen(plain), because due to the condition you have set in your outer for loop, the latter will not execute if x takes on this value.

2
  • Thanks, I've implemented some of these changes. From what I can see the output doesnt change... but check50 passes now. Also after adding ctype.h and a isalpha() passes last test :) sandbox.cs50.net/checks/05b7ce6a334a4bf59f5297d3a0b15ba9 Commented Sep 4, 2014 at 12:37
  • Sweet, please give me an upvote if my answer sufficed to solve your problem. :)
    – pat_krat
    Commented Sep 4, 2014 at 13:00

You must log in to answer this question.

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