title: How to use strtok() to read from a text file and create structs?
body: <p>Given a text file:</p>
  
  <pre><code>I Angelina Jolie 1 7728323
  I Mel Gibson 3 7809606 7733889 7724609
  I Robert Redford 2 7721170 7731959
  I Jennifer Aniston 4 2188989 2189898 2181020 2183456
  I Jami Gertz 4 7734404 7774012 7773023 7921492
  I Brad Pitt 2 7774017 7878485
  R Sylvester Stallone 0 
  I Victoria Principal 3 7933045 7771234 7820987
  R Jennifer Aniston 0
  R Sean Penn 0
  I Kevin Costner 1 7874014
  Q
  </code></pre>
  
  <p>I need to read each line, separate the values by spaces, and create structs of each one.  My current code is:</p>
  
  <pre><code>int main(){
  int y;
  FILE *data;
  char action;
  char line[100];
  int counter = 0;
  int index = 0;
  
  struct number{
      int phoneNumber;
      struct number *next;
  };
  
  struct contact{
      char fName[10];
      char lName[10];
      struct number *start;
  };  
  
  struct number numbers[50];
  struct contact directory[10];
  
  if((data=fopen("hw6data.txt", "r")) != NULL){
      while(fscanf(data, "%s", line) != EOF){
          char s[2] = " ";
          char *token;
  
          token = strtok(line, s);
  
          while(token != NULL){
              if(counter==0){
                  if(s == "I") {
                      if(counter==1){
                          strcpy(directory[index].fName, s);
                      }
                      if(counter==2){
                          strcpy(directory[index].lName, s);
                      }
                  }
              }
              token = strtok(NULL, s);
          }
      }
  }
  
  for(y = 0; y &lt; 10; y++){
      printf("%s ", directory[y].fName);
      printf("%s\n", directory[y].lName);
  }
  
  fclose(data);
  return 1;
  </code></pre>
  
  <p>}</p>
  
  <p>I'm trying to create a struct for each phone contact.  The I or R indicates whether I should insert the contact or remove it. The directory is an array that contains up to 10 contacts.  I can hold a total of 50 numbers.  Each contact struct holds a pointer that should point to the first number in the numbers array of number structs.  I'm creating an array-based linked list.  I thought this code should create the contact structs.  It compiles, but when I run it I get:</p>
  
  <pre><code> ��f
   �
  ɷ� 
  �E 
  
  ����� 
   �
  �� 
  .N=� 
   |�X�|���^�
  � 
  Segmentation fault
  </code></pre>
  
  <p>Help?</p>