CLion won't show output in Debug
Asked Answered
D

2

20

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.

Dietrich answered 12/12, 2017 at 15:26 Comment(0)
D
32

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

Dietrich answered 12/12, 2017 at 17:56 Comment(4)
There is indeed an issue with stdout buffering on Windows, we're aware of that (intellij-support.jetbrains.com/hc/en-us/community/posts/…). Thank you for posting the workaround here!Blayze
@EldarAbusalimov Seems the issue still exists in CLion 2019.3; As a side note, setbuf is deprecated, so anyone should use setvbuf instead.Toowoomba
it depends. setbuf seems to be working yet. and it is working just fine.Caudex
use setvbuf like this: setvbuf(stdout, NULL, _IONBF, 0);Wetzel
G
3

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

Gardas answered 7/2, 2020 at 11:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.