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
Troubleshooting Chromebook Not Charging
How to use pictures as Excel chart columns
Bleach: Characters with the most changed appearances
Why do phones need wireless charging?
How to create names with special characters, add special characters to game names, game character names
How to prevent laptop battery from charging past 80% on Windows 11