怎样将带有空格的字符串空格中间的内容分别赋给字符数组

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:16:30
CString str;
str.Format("jdfjksk akdkfj jjskf jakdf ");
char srr[10][16];
怎样才能让str中以空格相隔的字符赋给srr[];
请高手指教,我倾囊加分啊!
很感谢你的回答,但vc里并无此命令呀

srr[]=str.split(' ')

strtok,利用这个函数稍加改进就可以是一个非常不错的split函数。唯一的缺点就是需要提前知道你需要分成多少份,这个对有些人用起来不是很方便。我把改进过的代码贴出来。
#include <string.h>
#include <stdio.h>
int main(void)
{
char input[16] = "中国,dai,wen";
char *p;
/* strtok places a NULL terminator
in front of the token, if found */
/* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
p = strtok(input, ",");
if (p) printf("%s\n", p);
for(int i=0;i<2;i++)
{
p = strtok(NULL, ",");
if (p) printf("%s\n", p);
}
return 0;