strcmp() comparing parts

Hello, im trying to compair a text BEFORE a space is giving..

strcmp(msg, "/name") for example..


/name Hanno

how can i split /name and Hanno ?
in php there is a function called explode.. but isnt realy usefull this time :(

Hope someone got the right experiance to show me an example.

Best regards,
Hanno
Use strchr() to find the space:
char* pos = strchr(str, " ");
I managed to get it working with comparing:

if (!strncmp (msg,"/panelty",8))

strncpy can copy characters from a string, but how can i manage to copy character 9 to 20 in the string ?
Like this:
strncpy(buffer, (str + 9), 11);
Adding 9 to str2 makes the pointer you pass to strncpy 9 point literally to str2 + 9 elements.

Example:
1
2
3
4
char buffer[4] = {0};
const char* str = "Hello, world!";

strncpy(buffer, str + 9, 4);


Instead of "Hello, world!", strncpy would get "rld!".
Topic archived. No new replies allowed.