Page 1 of 1

Running C Programs in Zeus

Posted: Wed Dec 28, 2016 11:10 pm
by jussij
Consider this simple test.c program:

Code: Select all

#include <stdio.h>

int main()
{
    printf("Hello World.\n\n");
    printf("Press Any Key to Continue......\n");
    getchar();
    return 0;
}
If you compile, link and run this code inside Zeus you'll be presented with a console window that is empty.

Inside that console window pressing a key then results in this output capture inside Zeus:

Code: Select all

Hello World.

Press Any Key to Continue......
What is causing this strange behaviour is the running test.exe executable is buffering it's standard output.

To fix this behaviour make the following code change:

Code: Select all

#include <stdio.h>

int main()
{
    // stop stdout from being buffered 
    setbuf(stdout, NULL);

    printf("Hello World.\n\n");
    printf("Press Any Key to Continue......\n");
    getchar();
    return 0;
}
Cheers Jussi