title: C linked list creation from input file with output
body: <p>Hello I am creating a linked list in C to print the unique tokens given from a text file called dict.txt I am new to C and unsure how to properly read each word from the file, store it into a Node and then print the resulting linked list. Below are my following methods, I have omitted my contains method or its implementation into my add method. I am not concerned with that part yet, only trying to print every word from the given text file.</p>
  
  <pre><code>struct Node{
  
          char *data;
          struct Node *next;
  }
  
  typedef struct Node *node;
  
  Node createNode(){
          Node new;
          new = (Node)malloc(sizeof(struct Node));
          *new.next = NULL;
          return new;
  }
  
  void add(Node head, char data){     
          Node temp,p;
          temp = createNode();
          *temp.data = data;
          if(head == NULL) head == temp;
          else{
          p = head;
          while(*p.next != NULL) {
          //TODO contains method to catch duplicates
          p = *p.next;
          }
          *p.next = temp;
          }
          return head;
          }
  int main(){
          File *filep;
          filep = fopen("dict.txt", "r");
          Node head = NULL;
  
          while(fscanf(filep, "%s", word) != EOF){
          int i = 0;
          if (i == 0) Node parent = add(head, word); //add the first word
          else{
          //how should I add the other nodes?
          }
          i++
  }
  </code></pre>
  
  <p>I am struggling to add a Node given the previous node in the while loop. Any suggestions? is my implementation incorrect? I am willing to change my methods around if it better suits the linked list data structure. thanks</p>