title: CSV into array in C
body: <p>I'm trying to load a CSV file into a single dimentional array. I can output the contents of the CSV file, but in trying to copy it into an array I'm having a bit of trouble.</p>
  
  <p>Here is my existing code, which I realise is probably pretty bad but I'm teaching myself:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define MAX_LINE_LENGTH 1024
  #define MAX_CSV_ELEMENTS 1000000
  
  int main(int argc, char *argv[])
  {
      char line[MAX_LINE_LENGTH] = {0};
      int varCount = 0;
      char CSVArray[MAX_CSV_ELEMENTS] = {0};
  
      FILE *csvFile = fopen("data.csv", "r");
  
      if (csvFile)
      {
          char *token = 0;
          while (fgets(line, MAX_LINE_LENGTH, csvFile)) 
          {
              token = strtok(&amp;line[0], ",");
              while (token)
              {
                  varCount++;
                  CSVArray[varCount] = *token; //This is where it all goes wrong
                  token = strtok(NULL, ",");
              }
          }
          fclose(csvFile);
      }
      return 0;
  }
  </code></pre>
  
  <p>Is there a better way I should be doing this? Thanks in advance!</p>