title: C split string into token by delimiter and save as variables
body: <p>I want to split a string into tokens and save data into variables.
  I have the following string:</p>
  
  <p><code>John|Doe|Melbourne|6270|AU</code></p>
  
  <p>I need to split it by <code>|</code> and every token keep as variable so I can use them in my program, like:</p>
  
  <pre><code>fname = "John"
  lname = "Doe"
  city = "Melbourne"
  zip = "6270"
  country = "AU"
  </code></pre>
  
  <p>tried this so far, I can access first token the rest I don't know how (besides a while loop that doesn't help me):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main (void) {
  char str[] = "John|Doe|Melbourne|6270|AU";
  
  strtok(str, "|");
  
  printf("%s\n", str);
  return 0;
  }
  </code></pre>