title: Split a string that I read from a file
body: <p>I have a file like this</p>
  
  <pre><code>GET /index.html k
  GET /docencia.html k
  GET /ejemplo.html k
  </code></pre>
  
  <p>and I want to read it line by line and split it up with this delimiter <code>" "</code> but is giving me this error: <code>segmentation fault(core dumped)</code> and I don't know what to try.</p>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char *argv[]) {
      char ordenes[150];
      char *orden[3];
      char *token;
      int tok;
  
      FILE *fp;
      fp = fopen(argv[1], "r");
      if (fp == NULL) {
          printf("File error");
          exit(1);
      }
  
      while (feof(fp) == 0) {
          fgets(ordenes, sizeof(ordenes), fp);
          printf("%s \n", ordenes);
          token = strtok(ordenes, " ");
          tok = 0;
          while (token != NULL) {
              orden[tok] = strdup(token);
              tok++;
              token = strtok(NULL, " ");
          }
  
          printf("\n%s\n", orden[0]);
          printf("\n%s\n", orden[1]);
          printf("\n%s\n", orden[2]);
      }
      fclose(fp);
  }
  </code></pre>
  
  <p>The error shows when I call the first <code>strdup</code>. If I try to print the token just after I call the first <code>strtok</code>, it fails too (the same <code>segmentation fault core dumped</code>) so I guess the problem is with the <code>strtok</code>.</p>