Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion - Carriage return? \r

I am using the CLion IDE and I am trying to do a carriage return.

I am doing a print statement in C and have the following syntax:

printf("\rHello World!"); which is inside a loop. The loop still prints every Hello World on its own line. There are no \n's in my program. I've tried changing the line separators options to unix mac OS and windows and none of them change the functionality. Google has also led me to no useful answers.

int main()
{
    int i = 0;
    while (i < 5000000)
    {
        printf("\rThis is line number %d!", i++);   
    }

    return 0;
}

My expected output is only a single line of text in the console window.

Thanks.

like image 896
Hatefiend Avatar asked May 06 '17 21:05

Hatefiend


1 Answers

Your problem is PuTTY console, that is used in CLion by default. You can switch it off in Registry:

Help | Find Action | Registry... =>
run.processes.with.pty [ ] <- uncheck

I recommend you modify the program:

#include <iostream>

int main() {
    int i = 0;
    while (i < 500) {
        printf("\rThis is line number %d!", i++);
        fflush(stdout); // <- add this call
    }

    return 0;
}
like image 163
uta Avatar answered Nov 18 '22 05:11

uta