title: How to point a double-pointer header to a linked list?
body: <p>I am writing a program that takes strings from lines of a file, and passes them into a linked list of char arrays/C-style strings.</p>
  <p>Here is the struct/typedef I am using:</p>
  <pre><code>struct linked_list {
      char *string;
      struct linked_list *next;
      };
  typedef struct linked_list Node;
  </code></pre>
  <p>Now, the function where I am processing the file is the following snippet:</p>
  <pre><code>void function(char *filename, Node **header) {
      FILE *fp;
      fp = fopen(filename, &quot;r&quot;);
      if (fp != NULL) {
          int line_count = 0;
          Node *curr = NULL;
          char* line = NULL;
          size_t len = 0;
          ssize_t read;
          while ((read = getline(&amp;line, &amp;len, fp)) != -1) {
              printf(&quot;File got: %s\n&quot;, line);
              curr = (Node*)malloc(sizeof(*curr);
              curr-&gt;name = malloc(line);
              strcpy(curr-&gt;name, line);
              printf(&quot;Curr added: %s\n&quot;, curr-&gt;name);
              if (line_count == 0) {
                  *header = curr;
                  printf(&quot;Header assigned curr\n&quot;);
              curr = curr-&gt;next;
              line_count++;
          }
          header = &amp;curr;
      }
  </code></pre>
  <p>The prints confirm that I am successfully assigning the variables. Next, the function to print is as follows:</p>
  <pre><code>void print(Node *header) {
      while (header != NULL) {
          printf(&quot;%s\n&quot;, header-&gt;name);
          header = header-&gt;next;
      }
  }
  </code></pre>
  <p>Which obviously doesn't work because the header doesn't properly point to the list.</p>
  <p>How would I go about fixing this? I have tried some things like trying to point the header to the linked list &quot;curr&quot; before adding any values, but that didn't seem to work.</p>
  <p>I am new to C, so some syntax may be rough/inefficient (especially the malloc() functions, but I will get to that later.</p>
  <p>Here is the main function:</p>
  <pre><code>int main(int argc, char* argv[]) {
      Node* header = NULL;
      function(argv[i], &amp;header);
      print(header);
      return 0;
  }
  </code></pre>