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:

  1. you need have #include <string.h> header included in code use function.
  2. the str[first argument] should not constant or read-only literal. strtok() may need modify input argument.
  3. if compiler supports, can use strtok_r() provided compiler extension have reentrant version of strtok().

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -