title: How do I split a text file and store them in arrays to use for a template in C?
body: <p>I'm a newbie at C and I'm having problems splitting a particular text file and storing the tokens in an array.</p>
  
  <p>This is my txt file called data.txt- to be splitted by "|":</p>
  
  <pre><code>Public|Jane|Q|Ms.|600|Maple Street|Your Town|Iowa|12345
  Penner|Fred|R|Mr.|123|that Street|Winnipeg|MB|R3T 2N2
  Gardner|Mark|E|Mr.|76|The Avenue|Toronto|ON|M5W 1E6
  Acton|Hilda|P|Mrs.|66|What Blvd|Winnipeg|MB|R3T 2N2
  </code></pre>
  
  <p>My code is :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define INPUT_LENGTH 128
  #define FIELD_LENGTH 30
  #define NUM_FIELDS   9
  
  int main( int argc, char *argv[] )
  {
    FILE *template = NULL;
    FILE *data = NULL;
  
    char input[INPUT_LENGTH];
    char customerData[NUM_FIELDS][FIELD_LENGTH];
    int  element = 0;
    char *next;
    char ch;
  
    template = fopen( "template.txt", "r" );
    if ( template != NULL )
    {
      // read in the customers until we're done
      data = fopen( "data.txt", "r" );
      if ( data != NULL )
      {
  
        //next = strtok(data, "|");
        while(fgets(input, INPUT_LENGTH,data) != EOF){
          next = strtok(input, "|"); //splitting the data stored in input by |
          while(next != NULL){
            strcpy(customerData[element],next);
            //customerData[element++] = next;
            next =strtok(NULL, "|");
            //element++;
          }
  
          //testing
          for(element=0; element&lt;INPUT_LENGTH; element++){
            printf("%s\n", customerData[element]);
          }
          //printf("%s\n", input );
  
        }
  
  
  
        fclose( data );
      }
  
      fclose( template );
    }
  
    return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>doing it like this give me an error <code>array type 'char [30]' is not assignable</code> and a bunch of garbage output. I need help in knowing what I'm doing wrong in the splitting part.</p>
  
  <p>There are other stuff in the code because the main purpose of my program is to split these files, store the in an array and use each position for my template:
  separate template.txt file:</p>
  
  <pre><code>Welcome back, $1!
  We hope that you and all the members
  of the $0 family are constantly
  reminding your neighbours there
  on $5 to shop with us.
  As usual, we will ship your order to
     $3 $1 $2. $0
     $4 $5
     $6, $7 $8
  </code></pre>
  
  <p>for the first token, the output should be like:</p>
  
  <pre><code>Welcome back, Jane!
  We hope that you and all the members
  of the Public family are constantly
  reminding your neighbors there
  on Maple Street to shop with us.
  As usual, we will ship your order to
      Ms. Jane Q. Public
      600 Maple Street
      Your Town, Iowa 12345
  </code></pre>