C strtok() Function: Tokenizing Strings with Delimiters
The ///'strtok///' function is a function in the C programming language that is used to tokenize or split a string into smaller parts based on a delimiter. It is defined in the ///'string.h///' header file. //n//nThe function takes two arguments: the string to be split and the delimiter character. It returns a pointer to the first token found in the string. Subsequent calls to ///'strtok///' with a NULL pointer as the first argument will return the next token in the string. //n//nHere is an example of how ///'strtok///' can be used: //n//nc//n#include <stdio.h>//n#include <string.h>//n//nint main() {//n char str[] = ///'Hello,World,How,Are,You///';//n char *token;//n//n // Split the string into tokens based on comma delimiter//n token = strtok(str, ///',///');//n while (token != NULL) {//n printf(///'%s//n/// ', token);//n token = strtok(NULL, ///',///');//n }//n//n return 0;//n}//n//n//nOutput://n//nHello//nWorld//nHow//nAre//nYou//n//n//nIn this example, the string ///'Hello,World,How,Are,You///' is split into tokens using the comma delimiter. The ///'strtok///' function is called with the string and delimiter as arguments. The first call returns the first token ///'Hello///' and subsequent calls return the remaining tokens until there are no more tokens left.
原文地址: https://www.cveoy.top/t/topic/pWZe 著作权归作者所有。请勿转载和采集!