title: dealing with array of linked list
body: <p><strong>My approach:</strong></p>
  
  <p>An array of fixed-length (lets say 20) each element is pointer to the first node of a linked list.
  so i have 20 different linked list.</p>
  
  <p>This is the structure:</p>
  
  <pre><code>struct node{
         char data[16];
         struct node *next;
  };
  </code></pre>
  
  <p>My declaration for that array</p>
  
  <pre><code>struct node *nodesArr[20];
  </code></pre>
  
  <p>now to add a new node to one of the linked list, i do this:</p>
  
  <pre><code>struct node *temp;
  
  temp = nodesArr[i]; // i is declared and its less than 20
  addNode(temp,word); // word is declared (char *word) and has a value ("hello")
  </code></pre>
  
  <p>The addNode function:</p>
  
  <pre><code>void addNode(struct node *q, char *d){
      if(q == NULL)
          q = malloc(sizeof(struct node));
      else{
          while(q-&gt;next != NULL)
              q = q-&gt;next;
  
          q-&gt;next = malloc(sizeof(struct node));
          q = q-&gt;next;
      }
  
      q-&gt;data = d; // this must done using strncpy
      q-&gt;next = NULL; 
  }
  </code></pre>
  
  <p>and to print data from the array of linked list, i do this:</p>
  
  <pre><code>void print(){
      int i;
      struct node *temp;
  
      for(i=0 ; i &lt; 20; i++){
          temp = nodesArr[i];
          while(temp != NULL){
              printf("%s\n",temp-&gt;data);
              temp = temp-&gt;next;
          }
      }
  }
  </code></pre>
  
  <p>now compiler gives no error, the program run and i pass the data to it, and when i call print it doesn't print any thing,,??</p>
  
  <p><strong>UPDATE::</strong></p>
  
  <p>after I edited the code (thx for you), i think the problem in the print function,, any idea ?</p>