该字符串由数字和分隔符构成,能否帮小弟编一个类,该类能识别分隔符,并且把分隔符前后的数字转化到double型数组中的元素。
在线等待你的回复。谢谢了!

解决方案 »

  1.   

    如果知道数字的个数,可以用sscanf得到,如果数字的个数是未知的,那么只有查询所有的分割符了
      

  2.   

    这个函数保证可以:
    char** ExtractStr(char *source, char *seprator, int *count)
    {
    int i;
    char *token;
    char **pstr;
        char *string;
        char **ptr; *count=0;

    pstr=(char **)malloc(200*sizeof(char *));
    ptr=pstr;

    string=(char *)malloc(200*50);

    for(i=0;i<200;i++)
    pstr[i]=string+i*50;

    token = strtok(source, seprator);

    if(token!=NULL)
    {
    strcpy(*ptr, token);
    (*count)++;
    *ptr++;

    while(token!=NULL)
    {
    token = strtok(NULL, seprator);

    if(token!=NULL)
    {
    strcpy(*ptr, token);
    (*count)++;
    *ptr++; 
    }
    }
    }

    if(*count==0)
    {
    free(pstr);
    return NULL;
    }
    else
    return pstr;
    }此函数的返回值是一个字符串数组,每个字符串就是被seprator分开的source的子串,然后就简单了.对每个子串使用函数atof,就转换成了double数组了,count就是子串的个数.