1

I'm newbie in C. I want to compare string that I use '#DEFINE' and char buf[256]. This is my code.

#define SRV_SHOWMENU "SRV_SHOWMENU"
#define SRV_LOGIN_TRUE = "SRV_LOGIN_SUC"
#define SRV_LOGIN_FAIL = "SRV_LOGIN_FAIL"
#define SRV_REGISTER_OK = "SRV_REGISTER_SUC"
#define SRV_REGISTER_FAIL = "SRV_REGISTER_FAIL"
char buf[256];      // buffer for client data
...
...
...
...
...
...
if(strcmp(buf,SRV_SHOWMENU) == 0 || strcmp(buf,SRV_REGISTER_FAIL) == 0)
{

}

My C compiler tell me the systax error that "../src/server.c:417: error: expected expression before ‘=’ token". But if I change to "if(strcmp(buf,SRV_SHOWMENU) == 0)" just one compare is ok.

Thank you.

1
  • 7
    Remove the = signs in lines 2 to 5. Commented Aug 30, 2010 at 14:35

2 Answers 2

6

You don't need to use '=' sign after #define. You can read more here.

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

Comments

4

As already said, remove the = signs in the #defines

#define SRV_SHOWMENU "SRV_SHOWMENU" 
#define SRV_LOGIN_TRUE "SRV_LOGIN_SUC" 
#define SRV_LOGIN_FAIL "SRV_LOGIN_FAIL" 
#define SRV_REGISTER_OK "SRV_REGISTER_SUC" 
#define SRV_REGISTER_FAIL "SRV_REGISTER_FAIL" 
char buf[256];      // buffer for client data 
... 
if(strcmp(buf,SRV_SHOWMENU) == 0 || strcmp(buf,SRV_REGISTER_FAIL) == 0) 
{ 

}

With the = in, the pre compiler will turn if(strcmp(buf,SRV_SHOWMENU) == 0 || strcmp(buf,SRV_REGISTER_FAIL) == 0) into

if(strcmp(buf,"SRV_SHOWMENU") == 0 || strcmp(buf,= "SRV_REGISTER_FAIL") == 0) 

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.