C How to get the text after the space -
i have 2 words , separated space . how can use / print second word (the 1 comes after space?) have @ time :
if (strncmp(buf,"hi",3) == 0) printf("first word detected");
please have @ strtok()
function.
as per man page,
the strtok() function parses string sequence of tokens.
the syntax
char *strtok(char *str, const char *delim);
where, str
denotes mutable string , delim
list of characters used delimiter.
in case, can use space " "
delimiter.
hint: second word, need iterate more once. check syntax of doing man page.
notes:
- you need have
#include <string.h>
header included in code use function. - the
str
[first argument] should not constant or read-only literal.strtok()
may need modify input argument. - if compiler supports, can use
strtok_r()
provided compiler extension have reentrant version ofstrtok()
.
Comments
Post a Comment