title: Extracting integers from string and saving them into linked lists
body: <p>I wrote a code that saves contents from a file to a linked list.
  However I want to extract the ages and save them into a int array.
  For example Martha will be stored into name and 12 will be stored into age.</p>
  
  <p>I have been thinking about ways to implement it but I can't come up with a proper solution.</p>
  
  <p>The code below stores martha 12 into a char array. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt; 
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt; 
  #include &lt;string.h&gt;
  #define MAXN 50    
  #define val 2
  typedef struct node {
      char name[MAXN];
      //int value[val];
      struct node *next;
  }
  node;
  
  int main (int argc, char **argv) {
  
      FILE *file = argc &gt; 1 ? fopen (argv[1], "r") : stdin;
      if (file == NULL)
          return 1;
  
      char buf[MAXN];
     // int buf2[val];
  
      node *first = NULL, *last = NULL;   
  
  
      while (fgets (buf, MAXN, file)) {
  
          node *head = malloc (sizeof(node));
          if (head == NULL) {         
              perror ("malloc-node"); 
              return 1;   
          }
  
  
          buf[strcspn(buf, "\n")] = 0;    
  
  
          strcpy (head-&gt;name, buf);
          head-&gt;next = NULL;
  
  
          if (!last)
              first = last = head;
          else {
              last-&gt;next = head;
              last = head;
          }
  
  
      }
  
      if (file != stdin)  
          fclose(file);
  
      node *ptr = first;              
      while (ptr != NULL) {           
          node *node_t = ptr;         
          printf ("%s\n", ptr-&gt;name); 
          ptr = ptr-&gt;next;            
          free (node_t);              
      }
  
      return 0;
  }
  </code></pre>
  
  <p>This is the input file:</p>
  
  <pre><code>Martha 12
  Bill 33
  Max 78
  Jonathan 12
  Luke 10
  Billy 16
  Robert 21
  Susan 25
  Nathan 20
  Sarah 22
  </code></pre>
  
  <p>Any Suggestions?
  Thank you in advance.</p>