在C语言中,分割字符串通常意味着根据某个特定的分隔符将字符串拆分成多个子字符串。以下是一个简单的函数,用于根据分隔符分割字符串,并返回一个包含子字符串的指针数组。
```c
include
include
include
char split_string(const char str, const char delim, int num_tokens) {
char token;
char str_copy = strdup(str); // 创建字符串的副本
char tokens = NULL;
int token_count = 0;
if (str_copy == NULL) {
return NULL;