title: Storing Pieces of a String using Strtok
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;string.h&gt;
  int main(void)
  {
      int menuswitch=1;
      int amountofstudents;
      int fname[50];
      int lname[50];
      int grade[50];
      int i;
      char studentinfo[100];
      printf("Enter Amount of Students: ");
      scanf("%d", &amp;amountofstudents);
      for (i=0;i&lt;amountofstudents;i++)
      {
          gets(studentinfo);
          strcpy(fname[i], strtok(studentinfo, " "));
          strcpy(lname[i], strtok(NULL, " "));
          strcpy(grade[i], strtok(NULL, " "));
      }
  </code></pre>
  
  <p>Alright need a little using strtok. I am trying to store pieces of an input string to sort later. I was thinking of using strtok to break the string then placing each piece in the corresponding array. Yet, every time I try I get an error in Visual Studios saying Access Violation. Thanks for the help ahead of time</p>
  
  <p>The error is </p>
  
  <pre><code>First-chance exception at 0x5120F7B3 (msvcr110d.dll) in Lab 2.exe: 0xC0000005: Access violation reading location 0x00000000.
  Unhandled exception at 0x5120F7B3 (msvcr110d.dll) in Lab 2.exe: 0xC0000005: Access violation reading location 0x00000000.
  </code></pre>
  
  <p>The input would be </p>
  
  <pre><code>FirstName Lastname 80(Grade)
  </code></pre>