title: Why can't I printf() to stdout in C without using fflush()?
body: <p>I recently started programming in C and something I can't seem to get my head around is the way stdout prints to screen.</p>
  
  <p>When I added all my statements in the main() function and used the printf() function everything worked well, all the printf() statements were able to print to stdout.</p>
  
  <pre><code>From Main.c
  ...
  #include "HeaderFile.h"
  int main(int argc, char * argv[]){
   ...
   printf("%c\n", testChar);
   return 0;/*End of execution. Returns 0 value and ends gracefully*/
  }
  ...
  </code></pre>
  
  <p>But when I started to modularize my code in different functions, I realised that I have to insert the fflush(stdout) function at the end of each printf() function in order for the print function to print out to stdout:</p>
  
  <pre><code>From ReadFile.c
  ...
  #include "HeaderFile.h"
  void readFileFunction(char* file){
   ...
   printf("%c\n", testChar);
   fflush(stdout);
   ...
  }
  ...
  </code></pre>
  
  <p>Header file:</p>
  
  <pre><code> /*This is the header file used by the Linked list program.*/
  /*This is the header file used by the Linked list program.*/
  #ifndef HEADERFILE_H   /* Include guard */
  #define HEADERFILE_H
  
  #include &lt;stdio.h&gt; /*including the stdio file inside the Main.c file. stdio.h is a header file, where this and other similar functions are defined.*/
  #include &lt;string.h&gt;/*including the string file inside the Main.c file. string.h is a header file, where this and other similar functions are defined.*/
  #include &lt;time.h&gt;/*including the time file inside the Main.c file. time.h is a header file, where this and other similar functions are defined.*/
  #include &lt;stdint.h&gt;/*including the stdint file inside the Main.c file. stdint.h is a header file, where this and other similar functions are defined.*/
  #include &lt;stdlib.h&gt;/*including the stdlib file inside the Main.c file. stdlib.h is a header file, where this and other similar functions are defined.*/
  #include &lt;errno.h&gt; /*including the errno file inside the Main.c file. errno.h is a header file, where this and other similar functions are defined.*/
  #include &lt;regex.h&gt;
  
  extern const char errorString[]; /*A string of characters. Indicates an error message when the program in-counters a problem during execution.*/   
  
  /*String constants used to match user input with a specific function.*/
  extern const char *string1;
  extern const char *string2;
  extern const char *string3;
  extern const char *string4;
  extern const char *string5;
  extern const char *string6;
  extern const char *string7;
  extern const char *string8;
  extern const char *string9;
  
  /*Node structure with character value and the next node.*/
  typedef struct node {
      char value;
      char type;
      struct node * next;
  } nodeStruct;
  
  /*function prototypes for every function being used in the code.*/
  int removeChar(nodeStruct ** head, char value);
  void readFileInit(char* file);
  void readFileFunction(char *file);
  void printList(nodeStruct * head) ;
  void push(nodeStruct ** head, char value) ;
  char tail(nodeStruct * head) ;
  char head(nodeStruct * head) ;
  int length(nodeStruct * head) ;
  int pop(nodeStruct ** head) ;
  int regularExpr (const char *patt, char *str) ;
  void append(nodeStruct ** head, char value) ;
  int insertAfter(nodeStruct ** head, char value, char value2) ;
  int insertBefore(nodeStruct ** head, char value, char value2) ;
  
  #endif // HEADERFILE_H
  </code></pre>
  
  <p>Would you please explain in details why this sudden difference?</p>