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
- DAY function in SQL Server
- MIN function in SQL Server
- MAX function in SQL Server
- SUM function in SQL Server
- The ord () function in Python
- RIGHT function in SQL Server
- Int () function in Python
- AVG function in SQL Server
- 6 Conditional Functions That Make Excel Spreadsheets Smarter
- Hex () function in Python
- ABS function in SQL Server
- SUM for Newbies Only: Excel Experts Use This Function Instead!
- The function id () in Python
- DATEPART function in SQL Server