你好!
如果要在 C 语言中分割字符串,你可以使用 strtok
函数。这是一个在 C 字符串库中的函数,它可以将一个字符串分割成多个字符串,并且你可以指定分割字符。
下面是一个简单的例子,它将字符串 "Hello World" 按照空格进行分割:
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello World";
char *ptr;
ptr = strtok(str, " ");
while (ptr != NULL) {
printf("%s\n", ptr);
ptr = strtok(NULL, " ");
}
return 0;
}
运行后,输出结果为:
Hello
World
希望这对你有帮助!