Aug 21, 2002 Thread: How do I clear screen in a C program? And we all know what 'undefined' means: it means it works during development, it works during testing, and it blows up in your most important customers' faces.' -Scott Meyers. Aug 06, 2015 coloured output display in c programming (dev c) - Duration: 2:31. Muhammad Saad 44,856 views. The first method is to use the C run-time system function. The system function invokes the cls command provided by the command interpreter to clear the screen. Example 2 The second method is to write a function to programmatically clear the screen using the FillConsoleOutputCharacter and FillConsoleOutputAttribute functions.
Function 'clrscr' (works in Turbo C++ compiler only) clears the screen and moves the cursor to the upper left-hand corner of the screen. If you are using the GCC compiler, use system function to execute the clear/cls command.
C programming code for clrscr
#include<stdio.h>#include<conio.h>
int main()
{
printf('Press any key to clear the screen.n');
{
printf('Press any key to clear the screen.n');
getch();
clrscr();
printf('This appears after clearing the screen.n');
printf('Press any key to exit...n');
printf('Press any key to exit...n');
getch();
return0;
}
return0;
}
In the program, we display the message (Press any key to clear the screen) using printf and ask the user to press a key. When the user presses a key screen will be cleared and another message will be printed. Function clrscr doesn't work in Dev C++ compiler. Use the cleardevice function instead of clrscr in graphics mode.
Clear screen in C without using clrscr
#include <stdio.h>#include <stdlib.h>
int main()
{
printf('Press any key to clear the screenn');
getchar();
{
printf('Press any key to clear the screenn');
getchar();
Dev C++ Clear Screen Command
system('clear');// For Windows use system('cls');
return0;
}
return0;
}
heyy friends..
i m a beginner in C++ and am currently workin wid a program..
i m a beginner in C++ and am currently workin wid a program..
just for clrscr(), i have to include the whole conio.h file in my program inorder to clear the screen..
so is there any alternative to clrscr()??
please throw some light on this topic.. :)
so is there any alternative to clrscr()??
please throw some light on this topic.. :)
Dev C++ Clear Screen
- 5 Contributors
- forum 10 Replies
- 1,987 Views
- 1 Day Discussion Span
- commentLatest Postby MajesticsLatest Post
Dev C Clear Screen
Lerner582
To my knowledge, there is no standard way to clear the screen in C/C++, because that's not the way the console was designed. If you want to clear the screen then you have to do it using some non-standard way. You can write your own function to do this or use a third party function like clrscr(). I'll be happy to learn along side you if I'm wrong.