title: c getline() - how do I parse a line?
body: <p>I'm at a loss as far as how to parse the line in getline(). I would like look at each char that is in the line. </p>
  
  <p>So if someone were to type in: "Hello" into stdin, I'd like to be able to able to access the char array in this manner: </p>
  
  <pre><code>line[0] = 'H' 
  line[1] = 'e' 
  line[2] = 'l'
  line[3] = 'l'
  line[4] = 'o'
  line[5] = '/0';
  </code></pre>
  
  <p>I've looked at getchar(), but I want to try and use getline() as I feel like it is more convenient. I've also looked at scanf(), but it skips whitespaces and doesn't let me parse the input as nicely as getchar() or getline().</p>
  
  <p>Here is simple code that attempts at getting the first char of a line via stdin, but results in a seg fault:</p>
  
  <pre><code>#include &lt;stdio.h&gt;                                                                                                
  #include &lt;stdlib.h&gt;                                                                                               
  
  int main()                                                                                                        
  {                                                                                                                 
    int len;                                                                                                        
    int nbytes = 100;                                                                                               
    char *line = (char *) malloc (nbytes + 1);                                                                      
  
    while(getline(&amp;line, &amp;nbytes, stdin) &gt; 0){                                                                      
      printf("first char: %s", line[0]);  //try and get the first char from input
  
      /**
       * other code that would traverse line, and look at other chars 
       */                                                                         
    };                                                                                                              
  
    return 0;                                                                                                       
  } 
  </code></pre>
  
  <p>Thanks.</p>