title: linked list usage to obtain data from file
body: <p>i have a text file with emails addresses present.</p>
  
  <p>i want to obtain those emails and store it in any data structure or variable.
  Then i need to select mail address from random from the data structure.</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include &lt;stdlib.h&gt;
  #include&lt;string&gt;
  
  struct link_list
  {
      char mail[50];
      int counter;
      struct link_list *next;
  };
  typedef struct link_list node;
  
  
  void main()
  {
  FILE *fp ;
  char string1[80];
  node *head;
  int count_length=0;
  char *fname = "email.txt";
  fp = fopen ( fname, "r" ) ;
  char line [ 128 ]; /* or other suitable maximum line size */
  int count=0;
  
  while ( fgets ( line, sizeof line, fp ) != NULL ) /* read a line */
  {
      count++;
      if(head==NULL)
      {
          head=(node *)malloc(sizeof(node));
          fscanf(fp,"%s",string1);
          strcpy(head-&gt;mail,string1);
          head-&gt;counter=count;
          head-&gt;next=NULL;
  
      }
      else
      {
      node *tmp = (node *)malloc(sizeof (node));
      fscanf(fp,"%s",string1);
      strcpy(tmp-&gt;mail,string1);
      tmp-&gt;next = head;
      tmp-&gt;counter=count;
      head = tmp;
  
      }
  
  }
  
  fclose(fp);
  fp = fopen ( fname, "r" ) ;
  
  fclose(fp);
  //printf("%d",count_length);
  getch();
  }
  </code></pre>
  
  <p>I edited the code..i am getting assertion error</p>