title: C's printf and fprintf(stdout,) are not printing
body: <p>This is a bit of an odd one. My code wasn't outputting what I thought it should. I added some print statements at various stages to see where it was going wrong. Still nothing.
  So I added a printf statement at the start of main. That's where I got really confused.</p>
  <p>So I presumed something funny was happening with the file descriptors. I changed the <code>printf</code> to a <code>fprintf</code>. Still nothing. Printing to stderr with <code>fprintf</code> does work! Why is this happening?</p>
  <p>Removing all of the body from main except the initial print statement and the return does print.</p>
  <h3>Code</h3>
  <pre><code>int main(void) {
      fprintf(stdout, &quot;STARTED!&quot;);
      //Create an Internet domain socket
      int sockfd = socket(AF_INET, SOCK_STREAM, 0);
      //If this fails exit and print the error
      if (sockfd == -1) {
          printf(&quot;Error %d, cannot create socket&quot;, errno);
          return 1;
      }
      printf(&quot;SOCKET CREATED!&quot;);
  
      //Creates a socket address
      struct sockaddr_in  addr;
      addr.sin_family = AF_INET;
      addr.sin_port = htons(8080);
      addr.sin_addr.s_addr = INADDR_ANY;
  
      //Attempts to bind to the socket address, again prints to error if this fails.
      if (bind(sockfd, (struct sockaddr *) &amp;addr, sizeof(addr)) == -1)
      {
          printf(&quot;Error %d, cannot bind&quot;, errno);
          return 1;
      }
  
      //Starts Listening for a client
      if (listen(sockfd, 1) == -1)
      {
          printf(&quot;Error %d, cannot listen&quot;, errno);
          return 1;
      }
  
      //If all is successful, server is operational
      while(1)
      {
          //Creates a file descripter for the connection
          int connfd;
          //And a socket address for the client
          struct sockaddr_in cliaddr;
          socklen_t cliaddrlen = sizeof(cliaddr);
          //If a connection attempt is made accepts it.
          connfd = accept(sockfd, (struct sockaddr *) &amp;cliaddr, &amp;cliaddrlen);
          if (connfd == -1) {
              //If the connection fails print an error
              printf(&quot;Error %d, cannot accept connection&quot;, errno);
              continue;
          }
  
          //Otherwise process the request
          else {
              printf(&quot;CONNECTED!&quot;);
              char end;
              end = 1;
              while (end)
              {
                  process_request(connfd);
                  end = 0;
              }
          }
          close(connfd);
  
      }
      close(sockfd);
      return 0;
  }
  </code></pre>