title: read() stdin in c?
body: <p>I have a quick little question involving the read() command.</p>
  
  <p>I am really rusty in C, and unfortunately, my current assignment has me programming in C.
  We need to read stdin using the read() and not fgets and the like.</p>
  
  <p>So I have a simple while loop:</p>
  
  <pre><code>int n, i;
  char buffer[257], *input;
  
  while((n=read(fileno(stdin), buffer, 256)) &gt; 0)
                  {
                          buffer[n] ='\0';
                          if(buffer[n] = '\n') break;
                          write(input, buffer, strlen(buffer));
                  }
  </code></pre>
  
  <p>So I am not sure how to make this loop stop at the press of enter (end of line) so that's why I have the break code, though I don't know if that's done correctly.</p>
  
  <p>The whole objective I am trying to accomplish is to put the input from stdin into the pointer 'input'</p>
  
  <p>(I am really bad at understanding pointers so bear with me :) )</p>
  
  <p>My problem is that I am getting segmentation faults when I press enter.
  I wish I could use fgets because then all this would be solved with a simple</p>
  
  <pre><code>input = fgets(buffer, 256, stdin);
  </code></pre>
  
  <p>Darn homework :(
  Anyways, if any of you could point me in the right direction, I would really appreciate it. Thank you!</p>