0

I have troubles with the parse function in pset6 server.c. Only two items in the check fails. Im really struggling undertanding what the error messages means, anyone here that understands?

If the error is that method is abcGET or GETabc then my code checks for this(i think)abcGET;

> if(line[0]!='G' && line[1]!='E' && line[2]!='T' && line[3]!=' ')
>     {
>         error(405);
>         return false;
>     }

check50 abcGET GETabc

2
  • This return false;[ makes me wonder: did you type this code into the question, or copy/paste from the IDE? (because of the trailing '['). This code snippet on it's own looks fine.One possibility is this is not the exact code you are running. Or there is another problem in parse function causing the error. For instance, if you are testing for something like line[4] != '/' before this test, the program may be throwing a 501 and not even getting to this routine. Or something else entirely. Not enough info to evaluate more. debug50 and/or gdb are your friends. – DinoCoderSaurus Oct 7 '16 at 13:49
  • The return false;[ was just a typo in the comment. Thanks for the answer. – lkoks Oct 7 '16 at 14:34
1

This logic isn't right:

if(line[0]!='G' && line[1]!='E' && line[2]!='T' && line[3]!=' ')

For example, let's take GETabc:

     G != G   ? False  
     E != E   ? False  
     T != T   ? False  
     a != " " ? True  

False && False && False && True ====>  False

Because it's false, the body of the if block won't be executed.

What you want to use here is the OR logical operator, not AND.

3
  • Good example and good advice but it's not the whole story. abcGet will evaluate to True && True && True && True => True, but it too gives a check 50 error and returns 501. – DinoCoderSaurus Oct 8 '16 at 20:26
  • I agree with that! But the other interesting part (about his program possibly never getting to this routine) was already answered by you! hehe – Yuri Laguardia Oct 8 '16 at 20:38
  • DinoCoderSaurus: You just made my weekend! Thanks, it compiles now:) – lkoks Oct 9 '16 at 6:27

You must log in to answer this question.

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