title: Writing to stdin and reading from stdout (UNIX/LINUX/C Programming)
body: <p>I was working on an assignment where a program took a file descriptor as an argument (generally from the parent in an exec call) and read from a file and wrote to a file descriptor, and in my testing, I realized that the program would work from the command-line and not give an error if I used 0, 1 or 2 as the file descriptor.  That made sense to me except that I could write to stdin and have it show on the screen.  </p>
  
  <p>Is there an explanation for this?  I always thought there was some protection on stdin/stdout and you certainly can't fprintf to stdin or fgets from stdout.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  int main()
  {
      char message[20];
      read(STDOUT_FILENO, message, 20);
      write(STDIN_FILENO, message, 20);
  
      return 0;
  }
  </code></pre>