Home > Enterprise >  How can I clear console while running program in CLION
How can I clear console while running program in CLION

Time:12-01

Is it possible to clear the terminal while running the app in CLION? Operating system - macOS

I have tried system("clear"); and system("cls")

EDIT: With system("cls") it prints out sh: cls: command not found. And with system("clear") nothing happens. I also included <stdlib.h> library.

void gameAlgorithm(int difficulty)
{
    int number = rand() % difficulty;
    int guess = -1;

    while(guess != number)
    {
        printf("\nYour guess?: ");
        scanf("%d", &guess);
        if(guess < number)
        {
            printf("Number is HIGHER than %d.", guess);
        }else if(guess > number)
        {
            printf("Number is LOWER than %d.", guess);
        }
        system("clear");
    }
    printf("\nYOU ARE CORRECT!!!");
}

I wanted to learn about clearing the terminal while running the program. This is a basic "guess number" game. Each iteration has to clear the terminal (as I thought).

I have tried to run main.c in the terminal and it works fine. But is it possible to make the same thing on CLION?

CodePudding user response:

There are several methods to clear the console or output screen and one of them is clrscr () function. It clears the screen as function invokes. It is declared in “conio.h” header file.

  • Related