要求:
现有一串字符串: exp:afasdf#qerpo#asdfasdf#
可以根据任意字符char 对字符串分坼。
分坼后的结果放在数组中
比如上面例子:按#分册后的结果应该为
afasdf
qerpo
asdfasdf

解决方案 »

  1.   

    use  Cstring  find();
      

  2.   

    补充:ANSI 环境
    不要来mfc的东西
      

  3.   

    char ch='#';
    char str[]="afasdf#qerpo#asdfasdf#";
    char *p=str;
    for(i=0;i<strlen(str);i++)
    {
    if (str[i]==ch) 
    {
    str[i]='\0;
    printf("%s\n",p);
    p=p+i+1;
    }
    }以上代码可以输出你要的内容,如果要保存字符串,请自己添加代码
      

  4.   

    #include <string.h>
    #include <stdio.h>char string[] = "A string\tof ,,tokens\nand some  more tokens";
    char seps[]   = " ,\t\n";
    char *token;void main( void )
    {
       printf( "%s\n\nTokens:\n", string );
       /* Establish string and get the first token: */
       token = strtok( string, seps );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, seps );
       }
    }
      

  5.   

    strtokex:
    char sep[] = "#";//加入你想要的分隔符
    char *preslult;
    presult = strtok(sep, "你的字串");
    while(presult != NULL)
    {
    presult = strtok(NULL,"你的字串"); 
    }
      

  6.   

    输出结果:
    A string   of ,,tokens
    and some  more tokensTokens:
     A
     string
     of
     tokens
     and
     some
     more
     tokens
      

  7.   

    谢谢各位 要求都能达到
    能不能给一个函数输入输出呀。。我调用就可以了
    int pro_str( char * srcstr,char **deststr,unsigned char ch )
    {
    ...
    }
    说明:
    int 返回列数
    srcstr 输入参数
    deststr 输出数组
    ch 分册字符
      

  8.   

    好懒阿:)int pro_str( char * srcstr,char **deststr,unsigned char ch )
    {
       char *preslult;
       presult = strtok(ch, srcstr);
       int i = 0;//二维数组的第一维下标
       while(presult != NULL)
       {
         presult = strtok(NULL,srcstr);
         strcpy(*deststr + i * 第二维的长度, presult);   
       }}
      

  9.   

    char deststr[100][100]; //姑且
    int pro_str( char * srcstr,char **deststr,unsigned char ch )
    {
       char *preslult;
       presult = strtok(ch, srcstr);
       int i=0;
       while(presult != NULL)
       {
         presult = strtok(NULL,srcstr);
         strcpy(deststr[++i], presult);   
       }
      return i;
    }
      

  10.   

    我的程序在VC++ 6.0中编译通过
    void pro_str( char * srcstr,char deststr[], char* ch )
    {
       char *presult;
       presult = strtok( srcstr, ch);
       int i = 0;//二维数组的第一维下标
       while(presult != NULL)
       {
            strcpy(deststr + i++ * 100, presult);
            presult = strtok(NULL,ch);
            
       }}但在你是不是在纯C的环境下, 那样的话,数组参数可能要写成 char **desstr