分割字符串

#include<stdio.h>
#include<string.h>

void split(char str[],char * split)
{
	char * p;
	p = strtok (str,split);
	printf("%d\n",p);
	while(p!=NULL) {
		printf ("%s\n",p);
		p = strtok(NULL,split);
	}
}
int main()
{
	char a[] = "hello#world#abc";
 	char str;
 	int i;
 	for(i = 0;i<strlen(a);i++)
 	{
 	if((a[i]< 'a' || a[i] > 'z') && a[i]>'A' || a[i] < 'Z')
 	{
 	str = a[i];//第一种方法,找到分隔符 
 	//a[i] = '\n';//第二种方法,直接替换成‘\n’                
	 }
 	}
 	split(a,&str);//配合第一种方法使用
 	return;
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐