title: Storing input from user into linked list using array
body: <p>So I'm trying to get input from user and store it in linked list, using array (every 5 chars a new linked list is created). After getting EOF I want to print the input (actually print the arrays in each linked list)
  here is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define MAX 5
  
  
  
   typedef struct charNode {
      int arr[MAX];
      struct charNode *next;
  } charNode;
  
  
  void addNode();
  void printAll();
  
   
  
      int main(){
     int c,i;
     charNode *head=malloc(sizeof(charNode));
     charNode *current=head;
  
   while((c=getchar())!=EOF){
    while(i&lt;MAX){
    current-&gt;arr[i++]=c;
   }
   i=0;
   addNode(current);
   }
   printAll(head);
  
  
   return 0;
   }
   void addNode(charNode *current){
     struct charNode *link = (struct charNode*) malloc(sizeof(struct charNode));
       current-&gt;next =link;
       link-&gt;next = NULL;
     current=current-&gt;next;
   } 
  
   void printAll(charNode *head){
    int j=0;
    while(head-&gt;next!=NULL){
     while(j&lt;MAX){
      printf("\n %d \t",head-&gt;arr[j++]);
     }
      printAll(head-&gt;next);
    }
    return;
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>and I'm getting "Segmentation fault (core dumped)" error.. </p>