0

I am trying to implement a server with multiple commands. Most commands work so far except that I want the server to send a warning to the client when the client writes an argument to the quit command. (I.E. quit xyz) and lets the user try again rather than exiting the server. Unfortunately the server quits whether the user types quit or quit arguments.

bool done = false;

do
{
    if(strcmp(cmd, "quit") == 0)
    {
        if(strcmp(argument, "") != 0)
            strcpy(replyMsg, "504 Command not implemented for that parameter.\n");
        else
        {
            strcpy(replyMsg,"221 Service closing control connection.\n");
            done = true;
        }
    }
    while(strcmp(cmd, "quit") != 0 && done != true);
4
  • You are probably missing a } Commented Oct 15, 2013 at 19:05
  • There's a brace missing (closing brace of the do loop) Commented Oct 15, 2013 at 19:05
  • Thanks everyone. I found out that my mistake was in the client side and the missing bracket is just a typo. I don't know how to properly close topics or should I just delete it? Commented Oct 16, 2013 at 21:37
  • Up to you. You might also fix the typo in your question and add an answer to your own own question in which you explain what was wrong on the client side. In any case, I believe my own answer about the fact checking cmd is redundant still apply. Commented Oct 17, 2013 at 2:11

3 Answers 3

1

I would just use:

...
}
while(!done);

There is no point checking cmd.

Sign up to request clarification or add additional context in comments.

Comments

0

Your loop structure seems missing brace before while to be wrong, or it is a typo. Check it first and lets see the correct code.

Comments

0

Remove your test on the cmd in the while condition. Whenever he user chooses 'quit' it evaluates to false, so the whole expression is false due to the conjunction and the loop exits

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.