title: Read names from .txt File and add it to a linked list
body: <p>I want to create a linked list, wich contains names from a input.txt File.
  First name and last name are seperatet by a blank space and after the last name there is a linebreak.</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct node{
     char* firstname;
     char* lastname;
     struct node *next;
     }node;
  
  node *add(node *head, char* fnme, char* lnme){
     node *new_node;
     new_node = (node*)malloc(sizeof(node));
     if(new_node == NULL)
        printf(&quot;Fehler bei Speicher reservierung...&quot;);
     new_node-&gt;firstname = (char*)malloc(100*sizeof(char));
     if(new_node-&gt;firstname == NULL)
        printf(&quot;Fehler bei Speicher reservierung...&quot;);
     new_node-&gt;lastname = (char*)malloc(100*sizeof(char));
     if(new_node-&gt;lastname == NULL)
        printf(&quot;Fehler bei Speicher reservierung...&quot;);
  
     strcpy(new_node-&gt;firstname, fnme);
     strcpy(new_node-&gt;lastname, lnme);
  
     if(head == NULL){
        head = new_node;
        head-&gt;next = NULL;
        return head;
     }
  
     node *current;
     current = head;
  
     while(current-&gt;next != NULL){
        current = current-&gt;next;
     }
  
     current-&gt;next = new_node;
     new_node-&gt;next = NULL;
     return head;
   }
  
   void print(node *head){
     node *current;
     current = head;
  
     while(current != NULL){
       printf(&quot;%s %s\n&quot;, current-&gt;firstname, current-&gt;lastname);
       current = current-&gt;next;
      }
     }
  
  int main(){
  
    node *head = NULL;
  
    char character;
  
    FILE *fp;
    fp = fopen(&quot;input.txt&quot;, &quot;r&quot;);
  
    while ((character = fgetc(fp)) != EOF) {
    char *fnme, *lnme;
    fnme = (char*)malloc(100 * sizeof(char));
    if(fnme == NULL)
       printf(&quot;Fehler bei Speicher reservierung...&quot;);
    lnme = (char*)malloc(100 * sizeof(char));
    if(lnme == NULL)
       printf(&quot;Fehler bei Speicher reservierung...&quot;);
  
    int i = 0;
    while (character != ' ') {
       fnme[i++] = character;
       character = fgetc(fp);
    }
    fnme[++i] = '\0';   // NULL-terminate
  
    i = 0;
    while (character != '\n') {
       lnme[i++] = character;
       character = fgetc(fp);
    }
    lnme[++i] = '\0';  // NULL-terminate
  
    head = add(head, fnme, lnme);   
  
    free(fnme);
    free(lnme);
   }
   print(head);
   return 0;
  }
  </code></pre>
  <p>I never worked with strcat, somehow that doesnt work. I also tried using char-arrays instead of pointers but its the same result.
  Maybe I have to use other functions?</p>
  <h1>Update 1:</h1>
  <p>Somehow the Output is strange, seems like it's never going in the if-block in the add() function.
  Output with 2 names in the .txt-file:
  pt? pt?
  Peter Parker
  Klark Kent</p>
  <h1>Update 2:</h1>
  <p>Changed the Return type of the add() function, now it works :)</p>