我有array [2] [3] = {e-> id = m,
m-> t | e | null};

我正在尝试以两种方式分割字符串:如果找到'“”'(空白),则应该分割,如果找到“|”然后它也再次分裂。我知道这是不正确的,但是谁能帮助我呢?

for i=0 t0 row
   for j=0 to col
      c41= a[i][j].c_str();
      strcpy(pch55,c41);
      pch5=strtok(pch55,"|" || " "); // is it correct???
      for ( int u=0;pch5 != NULL;u++)
      {
          z33[u]= pch5;

          pch5 = strtok (NULL,"|" || " ");  //is it correct??

      }

最佳答案


pch5=strtok(pch55,"| "); // notice the space at the end

在第5行,以及
pch5=strtok(NULL, "| ");

在第10行。

strtok(3)的第二个参数是用作定界符而不是字符串定界符的字符集合。并且,NULL指示它从上次中断的地方继续。

07-24 21:28