title: How to parse an array in C
body: <p>I wanted to parse an input string (path) into the array.</p>
  
  <p>For example, if the input is </p>
  
  <blockquote>
    <p>cd("C/Hra/Halo 4/Hra");</p>
  </blockquote>
  
  <p>The array should contains <code>{"C","Hra","Halo 4","Hra"}</code>, but it contains <code>{"C","Hra","Halo 4,"HraC"}</code>.
  My friend suggested me to put <code>"\0"</code> for each string, but it doesn't work. </p>
  
  <p>Can someone please suggest me how to repair it? </p>
  
  <p>My code: </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include &lt;string.h&gt;
   void cd(char* path){
      printf("Path %s \n",path);
      int count = 0;
      int i = 0;
      int length = (int)strlen(path);
      for(i;i&lt;length;i++){
          if(path[i]=='/')
           count ++;
      }
    char foldersName[count][255];
    char str[strlen(path)];
    strcpy(str,path);
    char * pch;
    pch = strtok (str,"/");
    count = 0;
    while (pch != NULL)
    {
      strcpy(foldersName[count],pch);
      strcat(foldersName[count],"\0");
      pch = strtok (NULL, "/");
      count ++;
    }
    printf("----------------Tokens-----------\n");
    for(i =0;i&lt;count;i++){
      printf("%s \n",foldersName[i]);
    }
  }
  
   int main(int argc, char *argv[])
  {
  
     cd("C/Hra/Halo 4/Hra");
  
  }
  </code></pre>