Lucas Pires Lucas Pires - 4 months ago 20
MySQL Question

C: Pause page when full

i'm making a client database in C, and I couldn't find a way to when it lists all the people, when the console or the window is full, it pauses the printing to the screen and displays a message like "Press a key to display another page", in a way like vi can show the next page using a single press... If anyone knows how to get a quick around at this...

Answer

You could try to figure out how many rows your console has (On Linux: get the $ROWS variable from the environment). Then, before you print anything try to clear the console. You could use a call to system("cls"); //Windows orsystem("clear") //Linux or use the ASCII character printf("\033[2J");. This makes sure that you will start in the first row. Now you can simply use a loop like this:

for(int x = 0; x < TOTAL_ELEMENTS; x++)
{
    if(x < COLS)
    {
        puts(rows[x]);
    }
    else
    {
        printf("Press [ENTER] to show the next line")
        getchar();
        printf("\033[F\r"); // Go to beginning of previous line to override (Not that portable)
        puts(rows[x]);
    }
}

Otherwise, you can use a pager like more (Windows/Linux) or most/less (Linux) like @Eugene suggested in its comment

Comments