ENBYSS
ENBYSS

Reputation: 929

CLion won't show output in Debug

When I start up the program, this is the output:

-------------------- HASHMAP MANAGEMENT BOOT MENU -------------------------
Would you like to:
(a) create a new hashmap
(b) load an existing one
(q) exit
>

However, when debugging, none of this shows up. Checking the debug, it does go over the printf() commands, but it just refuses to let them show up in the console. Input registers, but output never comes.

int main(void){
    bool on = true;
    char choice = ' ';
    int status = 0;
    while(on){
        if(status == -1){
            printf("\n[ERROR] : HASHMAP NOT INITIALISED\n");
        }
        printf("\n-------------------- HASHMAP MANAGEMENT BOOT MENU -------------------------\n");
        printf("Would you like to:\n(a) create a new hashmap\n(b) load an existing one\n(q) exit\n> ");

        scanf("%c",&choice);
        ...
        ...
    }
}

This is how the start of the code is, excluding all the #includes. Also, for some reason, CLion says the code I'm building is task2-a.c | Debug if that's any help. task2-a.c being the name of the C file that's being built. I dunno what's going on...

Update: Debugging works great on Ubuntu 17.04 Clion 2017.2. It just doesn't work on Windows 10 CLion 2017.3.

Upvotes: 20

Views: 15830

Answers (3)

PhotonFalcon
PhotonFalcon

Reputation: 934

You can use fflush with the stream as an arg (like fflush(stdout)), or NULL as the arg to flush all streams. Using fflush solves this problem for me in CLion and you can add it directly to the logging macro, at an interval, or after the main loop.

I'd prefer not to mess with the buffer size just for printing in CLion, so setting setbuf isn't an option for me.

Upvotes: 0

s.demuro
s.demuro

Reputation: 439

If you don't care to use the built-in clion console, you can solve the issue by changing the default debugger used by clion.

Under Settings => Toolchain => <your compiler> => Debugger change Bundled GDB to your compiler's debugger, e.g. MinGW: Clion Settings

Upvotes: 3

ENBYSS
ENBYSS

Reputation: 929

Putting setbuf(stdout, 0); before any printf statement or any output happens fixed this problem.

Upvotes: 34

Related Questions