例如:char *str="asdr";
char *str2[10]={0};如何将str转换为str2,或赋给str2 ?

解决方案 »

  1.   

    str2[i] must malloc space firstly
      

  2.   

    two way:
    1.char *str="asdr";
    char *str2[0]= str;
    2. str2[0] = (char *)malloc(strlen(str));
     strcpy(str2[0], str);
      

  3.   

    const int Num = 10;char *str="asdr";
    char *str2[10]={0};
    for(int i=0;i<Num;i++)
    {
      str2[i] = new char [100];
      strcpy(str2[i], str);
      ShowMessage(str2[i]);
    }就是这样了!
      

  4.   

    就是说,先分配给内存空间,然后再用copy来转换。
      

  5.   

    char *str="asdr";
    char m_cChar;
    m_cChar = str[0] // m_cChar is 'a'
    m_cChar = str[2] // m_cChar is 'd'
    m_cChar = str[4] // m_cChar is NULLAbove is what you want ?