Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how can I clear the screen. clrscr () does not work.

0 votes
asked May 4, 2020 by Dácio Melo (190 points)
#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Hello World errado");
    clrscr();
    printf("Hello World correto");

    return 0;
}

3 Answers

0 votes
answered May 5, 2020 by sowmya8900 (180 points)

#include <stdio.h>
#include <stdlib.h>
#include<conio.h>      // clrscr() requires a header file of conio.h

int main()
{
    printf("Hello World errado");
    system("clear");           // if you are using GCC compiler / online compilers, use this instead of clrscr()
    clrscr();                    // if you are compiling on Turbo C++ compiler

    printf("Hello World correto");
    getch();
}

0 votes
answered May 5, 2020 by sofibilal193 (620 points)
Add #include<conio.h> header file and try it.
0 votes
answered May 5, 2020 by Eric VanSchaick (240 points)
the clrscr() function is in the conio.h library but that library isn't working with this compiler for some reason.  Therefor you can include the code for that function in your program yourself.

#include <stdio.h>
#include <stdlib.h>
//#include "conio.h"

void clrscr()
{
       printf("\x1b[2J");
}

int main()
{
    printf("Hello World errado");
    clrscr();
    printf("Hello World correto");

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...