The strtok () function in C
Char * strtok function (char * str, const char * delim) divides the string str into a sequence of tokens separately separated by delim separators (eg comma, ...).
Char * strtok function (char * str, const char * delim) divides the string str into a sequence of tokens separately separated by delim separators (eg comma, .).
Declare strtok () function in C
Below is the declaration for strtok () in C:
char * strtok ( char * str , const char * delim )
Parameters
str - The content of this string is modified and divided into smaller strings (tokens).
delim - This is the string containing Delimiter (only separators). They can be varied depending on the call.
Returns the value
This function returns the pointer to the last token found in the string. A null pointer is returned if no token is obtained.
For example
The following C program illustrates the usage of strtok () in C:
#include #include int main () { char str [ 80 ] = "Hoc C - co ban va nang cao - tai QTM" ; const char s [ 2 ] = "-" ; char * token ; /* lay token dau tien */ token = strtok ( str , s ); /* duyet qua cac token con lai */ while ( token != NULL ) { printf ( " %sn" , token ); token = strtok ( NULL , s ); } return ( 0 ); }
Compile and run C program and see the results.
According to Tutorialspoint
Previous article: Function strstr () in C
Next article: Ham strxfrm () in C
You should read it
- The strlen () function in C
- The strspn () function in C
- The strchr () function in C
- The strerror () function in C
- Memset () function in C
- The strrchr () function in C
- Function in programming C
- Beginners of computer programming need to focus on what?
- Strcpy () function in C
- Memmove function in C
- Top 20 free programming learning websites need to bookmark immediately!
- The strcoll () function in C
Maybe you are interested
Admire incredibly detailed images of the Orion Nebula through the eyes of the James Webb telescope This star 'tears up' its companion to create a rare beautiful nebula Admire the moment millions of new stars are born in the Lupus 3 nebula Top 15 free games on Steam gamers should experience Before 'returning to Thanos', what was the fate and appearance of Nebula in the comics? Spectacular views on Google Sky