Is there a way to clear screen after a while loop has taken place, so it starts program again but not at the bottom of the last text?
Brad.
Is there a way to clear screen after a while loop has taken place, so it starts program again but not at the bottom of the last text?
Brad.
#include <conio.h>
after declaration, with this command clrscr();
- - fUnKy F3m@le - -
You can use clrscr() like hermit suggested but I think this command is not supported on all systems. If it's not supported on your system you can always use the system command:
Code:system("cls");
And cls is supported on all systems is it? [/sarcasm]Originally posted by Monster
If it's not supported on your system you can always use the system command:
Code:system("cls");
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
i really like option 6! throw your monitor outta of the window!
ROLF
- - fUnKy F3m@le - -
>And cls is supported on all systems is it?
Technically, you could use conditional compilation to fix that. It's still pretty nasty, but portable:
-PreludeCode:#if SYSTEM == MSDOS #define CLRSCR system("cls"); #elif SYSTEM == POSIX #define CLRSCR system("clear"); /* etc... */
My best code is written with the delete key.
You're not listening... I said you could always use the system command.Originally posted by Hammer
And cls is supported on all systems is it? [/sarcasm]
... and the example you gave was specifically using cls, with no mention that that was OS dependant. A newbie might not spot that and could get confused when it didn't work.Originally posted by Monster
You're not listening... I said you could always use the system command.
And yes I was listening
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
A newbie should always read the manual pages. In the manual pages you can read how the function works...Originally posted by Hammer
... and the example you gave was specifically using cls, with no mention that that was OS dependant. A newbie might not spot that and could get confused when it didn't work.
And yes I was listening
But since manual pages are like FAQ pages (nobody reads it), you are probably right. I should have told that the cls command is an operating system command and can be different on any OS.
Option 1
#include <conio.h>
... code ...
clrscr();
... more code...
advantages:
clears the screen...
disadvantages:
... but only on MS-DOS systems with compilers that support it in this manner.
Who says there is a screen connected to standard output anyway?
Errors in FAQ:
nothing significant, except for not mentioning there might not be a screen.
Option 2
putcharing newlines and scrolling over
Advantages:
none
disadvantages:
there may not be a scree - printing 50 lines to the printer doesn't clear the screen
printing 50 lines to a 63 line screen also doesn't clear the screen
Errors in FAQ:
"It works" is wrong. It clearly doesn't work quite so widely as is implied by this phrase.
Option 3
Using a library to do it for you
Advantages:
You don't have to think about whether it works or not
Possibility of slightly portable code, but not universally portable code.
Disadvantages:
Getting a library to do the job
Getting a library which doesn't fall into the 'clearing the screen' errors
Who says there is a screen anyway?
Errors in FAQ:
Nothing significant for this bit, except for the possibility that there might not be a screen attached to stdout.
Option 4
Write directly to video memory
Advantages:
None
Disadvantages:
Highly platform dependent
Who says the program is outputting to that display device, to that framebuffer or even outputting anything to the screen at all?
Errors in FAQ:
Again, this certainly doesn't 'work' since it's completely non portable and depends heavily on the machine running it.
Option 5
Using curses on unix systems
Advantages
It works....
Disadvantages
... but only on unix systems which have curses.
Errors in FAQ:
None, but this is really a special case of option 3
My prefered answer is simply:
There is no way of doing it in C. No matter what you will need to use platform specific techniques. Find the techniques for your platform and use them, being aware that moving your code to other platforms (or even future or past versions of the same platform) might mean your code doesn't work.
Ian Woods
This should work w/o problems w/ the following conditions...Option 4
Write directly to video memory
Advantages:
None
Disadvantages:
Highly platform dependent
Who says the program is outputting to that display device, to that framebuffer or even outputting anything to the screen at all?
1. Platform is DOS.
2. Screen Resolution (text mode) 25×80 (25 rows by 80 cols)
#include<stdio.h>
main()
{
char far *vm= (char far *) 0xB8000000;
int i;
for(i=3998;i>=0;i-=2)
*(vm+i)=32; /* space character */
}
With little modifications u can run it for other text modes also.
-Harsha
Note of course that if the computer is in /any/ graphics mode or any other text mode this code won't work. It also doesn't work if I have specified a different page to be shown than the first one, and as you've specified, currently only works for a single text mode.Originally posted by vsriharsha
This should work w/o problems w/ the following conditions...
1. Platform is DOS.
2. Screen Resolution (text mode) 25×80 (25 rows by 80 cols)
... code ...
With little modifications u can run it for other text modes also.
-Harsha
The whole point of what I've said is that any technique for clearing the screen is non-portable and is often specific on many assumptions about the system you're using. You've coded a technique which suffers from the problems I stated for that option (writing directly to screen memory).
The cleanest way is to use the functions provided by your operating system/compiler vendor or to use a portable library like curses which (hopefully) will do things properly in a system specific manner.
Ian Woods
Last edited by hairyian; 05-02-2002 at 12:55 PM.