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
5 ★ | 1 Vote
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
Transparent solar cells help smartphones charge themselves with sunlight
How to charge phone with battery
6 reasons why phones charge slowly
iOS bug causes iPhone to crash when entering these 4 characters
Laptop automatically stops charging when playing games - Fast processing
How to properly plug in the iPhone charger according to Apple's recommendations