C语言的字符串操作
strtok 实现字符串切割: 将字符串根据分隔符进行切割分片.
代码语言:javascript复制#include <stdio.h>
int main(int argc, char* argv[])
{
char str[] = "hello,lyshark,welcome";
char *ptr;
ptr = strtok(str, ",");
while (ptr != NULL)
{
printf("切割元素: %sn", ptr);
ptr = strtok(NULL, ",");
}
system("pause");
return 0;
}
strlen 获取字符串长度:
代码语言:javascript复制#include <stdio.h>
int main(int argc, char* argv[])
{
char Array[] = "