Q: C program display order When I run the code below, it runs the system command on the 4th last line before displaying the string 'proceeding' before it! I'm wondering why and how to fix it, any ideas?
if ((strlen(command)>0) && (command[strlen (command) - 1] == '\n'))      
    command[strlen (command) - 1] = '\0';                               
    printf("proceeding");                  // <-- the string
    strcat(command,contents); 
    strcat(command,subject);
    system(command);                       // <-- offending system command
    sleep (1);
    printf("\n ----- Search complete for: [%s]",command);
    getchar();

There are of course variables such as 'command' and 'subject' which are manipulated and declared outside the code above, so If you need context than I will post the rest of the source code below.

A: Pull the chain and flush:
I.e.
After
printf("proceeding"); 

Put
fflush(stdout);

That will flush the stuff in the buffer (bowl!)
Before the system command is executed.

A: Try adding a '\n' to the printf.
It forces flushing the printf buffer. Otherwise, it is not necessary that printf immediately prints the passed params. You can google flushing the buffer latter

A: stdout is line buffered, so it will only display what's in the buffer after it reaches a newline
change printf("proceeding"); to printf("proceeding\n"); or flush stdout with fflush(stdout); will do the work.

A: The stdio stdout stream is line or fully buffered by default. To set it unbuffered (and to avoid having to write a fflush(stdout) after every output operation), use the ISO C setvbuf function declared in stdio.h:
setvbuf(stdout, (char *)NULL, _IONBF, 0);

once before doing the first I/O.
