18

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.

ENBYSS
  • 819
  • 1
  • 10
  • 22

2 Answers2

28

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

ENBYSS
  • 819
  • 1
  • 10
  • 22
  • 2
    There is indeed an issue with stdout buffering on Windows, we're aware of that (https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000740490-Where-did-the-black-windows-go-?page=1#community_comment_115000619510). Thank you for posting the workaround here! – Eldar Abusalimov Dec 14 '17 at 09:46
  • 3
    @EldarAbusalimov Seems the issue still exists in CLion 2019.3; As a side note, `setbuf` is deprecated, so anyone should use `setvbuf` instead. – Matze Jan 20 '20 at 15:38
  • it depends. setbuf seems to be working yet. and it is working just fine. – Oleg Kokorin May 05 '21 at 12:07
  • 2
    use setvbuf like this: `setvbuf(stdout, NULL, _IONBF, 0);` – Mattwmaster58 Sep 16 '21 at 20:10
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

s.demuro
  • 399
  • 2
  • 15