You are here

clrscr in C

"clrscr" function (works in Turbo C compiler only) clears the screen and move cursor to upper left hand corner of screen.

C programming code for clrscr

  1. #include<stdio.h>
  2. #include<conio.h>
  4. int main()
  5. {
  6.    printf("Press any key to clear the screen.\n");
  8.    getch();
  10.    clrscr();
  12.    printf("This appears after clearing the screen.\n");
  13.    printf("Press any key to exit...\n");
  15.    getch();
  16.    return 0;
  17. }

In the program first we display the message "Press any key to clear the screen." using printf and then ask the user to press a key. When user will press a key screen will be cleared and another message will be printed. clrscr function does not work in Dev C++ compiler. Also do not use clrscr in graphics mode instead use cleardevice.