title: Create an address book using a linked list
body: <p>I opened a thread yesterday asking about how I should proceed. Here is what I've got so far (sorry for the language, the program will be in Albanian but I'm sure you are getting the point).</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ctype.h&gt;
  
  void regjistrim();
  void kerkim();
  void modifikim();
  void fshirje();
  void rradhitje();
  void display();
  void load();
  
  #define EMRI 50
  #define MBIEMRI 50
  #define ID 20
  #define TEL 20
  #define EMAIL 25
  
  typedef struct node
  {
      char emri[EMRI];
      char mbiemri[MBIEMRI];
      char id[ID];
      char tel[TEL];
      char email[EMAIL];
      struct node* next;
  } node;
  
  FILE* addressbook;
  node* mynode;
  node* curr;
  
  int main(void)
  {
      char input[2];
      int choice;
  
      load();
  
      printf("----------------ADDRESS BOOK----------------");
      printf("\n\n\t1 - Regjistrimi i ri\n");
      printf("\n\t2 - Kerkim\n");
      printf("\n\t3 - Modifikim\n");
      printf("\n\t4 - Fshirje\n");
      printf("\n\t5 - Rradhitje\n");
      printf("\n\t6 - Afishim i address book\n");
      printf("\n\t0 - Exit\n");
  
      fgets(input, 4, stdin);
      sscanf(input, "%d", &amp;choice);
  
      while (choice &lt; 0 || choice &gt; 6)
      {
          printf("\nShtypni nje numer nga 0 - 6: \n");
          fgets(input, 4, stdin);
          sscanf(input, "%d", &amp;choice);
      }
  
      switch (choice)
      {
          case 1:
              regjistrim();
              break;
          case 2:
              kerkim();
              break;
          case 3:
              modifikim();
              break;
          case 4:
              fshirje();
              break;
          case 5:
              rradhitje();
              break;
          case 6:
              display();
              break;
          case 0:
              exit(0);
              break;
      }
  
      return 0;
  }
  
  void load()
  {
      addressbook = fopen("Addressbook.txt", "r");
  
      if (addressbook == NULL)
          printf("Could not open file.");
  
      node* mynode = malloc(sizeof(node));
  
      while (fscanf(addressbook, "%s %s %s %s %s", mynode-&gt;emri, mynode-&gt;mbiemri, mynode-&gt;id, mynode-&gt;tel, mynode-&gt;email) != EOF)
      {
          node* mynode = malloc(sizeof(node));
          mynode = mynode-&gt;next;
      }
      mynode = curr;
  }
  
  
  //Regjistron nje qytetar ne addressbook
  void regjistrim()
  {
      char input[2];
      char answer;
  
      do
      {
          node* newnode = malloc(sizeof(node));
  
          curr-&gt;next = newnode;
  
          addressbook = fopen("Addressbook.txt", "a+");
  
          printf("\nShtypni emrin: ");
          fgets(newnode-&gt;emri, EMRI, stdin);
  
          printf("\nShtypni mbiemrin: ");
          fgets(newnode-&gt;mbiemri, MBIEMRI, stdin);
  
          printf("\nShtypni ID-in: ");
          fgets(newnode-&gt;id, ID, stdin);
  
          printf("\nShtypni nr. telefoni: ");
          fgets(newnode-&gt;tel, TEL, stdin);
  
          printf("\nShtypni email-in: ");
          fgets(newnode-&gt;email, EMAIL, stdin);
  
          fprintf(addressbook, "Emri: %sMbiemri: %sID: %sNr. telefoni: %sEmail: %s\n", newnode-&gt;emri, newnode-&gt;mbiemri, newnode-&gt;id, newnode-&gt;tel, newnode-&gt;email);
  
          fclose(addressbook);
  
          printf("\nShtypni y/Y neqoftese doni te regjistroni person tjeter: ");
          fgets(input, 50, stdin);
          sscanf(input, "%c", &amp;answer);
  
          curr = newnode;
      }
      while(answer == 'y' || answer == 'Y');
  }
  
  void kerkim()
  {
      //TODO
  }
  
  void modifikim()
  {
      //TODO
  }
  
  void fshirje()
  {
      //TODO
  }
  
  void rradhitje()
  {
      //TODO
  }
  
  void display()
  {
      //TODO
  }
  </code></pre>
  
  <p>Currently I'm getting a segfault at this point: <code>while (fscanf(addressbook, "%s %s %s %s %s", mynode-&gt;emri, mynode-&gt;mbiemri, mynode-&gt;id, mynode-&gt;tel, mynode-&gt;email) != EOF)</code></p>
  
  <p>I am mainly concerned about the <code>load()</code> function which will load any entries to the linked list, if there are any, before the user does any action. </p>
  
  <p>Thank you in advance.</p>