-1

I am trying to implement an IF STATEMENT
in my C-Server.

read(client_fd,received_data,100);
printf("%s",received_data);

I want to print "ooo" if the received data equals to "test"

if (received_data == "test") {
printf('ooo');
}

?

The above example results in errors. (can't compile)

I don't know much C.

UPDATE :

Now I can compile fine ( after changing 'ooo' to "ooo" )
But although I am sending "test" to it.. if statement is not doing anything i think.

Joey
  • 15
  • 3
  • Multiple problems.. Strings in C have to be inside double quotes, characters are inside single quotes. You cannot compare strings using `==`, use `strcmp()` – Haris Feb 16 '17 at 11:45
  • "results in errors" — And what does the error message say? – Quentin Feb 16 '17 at 11:45
  • @Haris, using double quotes fixed compile errors. I sent "**test**" to it but if statement is not being triggered I think. I tried "**=**" instead of "**==**" .. compile errors. – Joey Feb 16 '17 at 11:50
  • @Joey, use `strcmp()`. In case of strings `=` or `==` will not work. – Haris Feb 16 '17 at 11:51

1 Answers1

1

The == doesn't work for const char *. Use strcmp instead.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
Piotr Kamoda
  • 956
  • 1
  • 9
  • 24