I want to be able to clear the screen after each input. how do i do this? how do i implement the dos command 'cls' in my c program. yes, i am a newbie.
: I want to be able to clear the screen after each input. how do i do this? : how do i implement the dos command 'cls' in my c program. : yes, i am a newbie. :
: : I want to be able to clear the screen after each input. how do i do this? : : how do i implement the dos command 'cls' in my c program. : : yes, i am a newbie. : : : : system("cls"); : :
@khaledelkhateeb said:
What is the difference between get char( );
get che ( );
get ch( ) ;
and get s();
getchar() takes one character
getche() would also take one character but would not display it on the screen
getch() is similar to getchar except that it is in conio.h
gets() would take a whole string and store it in a character array
It's a simple question, but there's no easy answer.
The core C language doesn't have a concept of screens. It has standard input ans standard output, which these days are almost always connected to DOS boxes or Unix terminals, but historically were often teletypes. So it sees output as a series of characters.
But the computer sees the DOS or Unix terminal as a program in its own right, and can treat it as an N x M raster of characters. conio.h or curses.h (for DOS or Unix) contain functions that do that.
Another answer, which has already been given, is to issue the system cls comand.
Another answer is that Ascii 0x0B, or form feed, will often be honoured, and move the terminal to a fresh screen.
You can also print lots of newlines
There is a very easy answer and here it is:
printf("\e[1;1H\e[2J");
or if you're like me and don't have any printf or stdio:
write(0,"\e[1;1H\e[2J",12);
--INFO--
The \e[1;1H sets your cursor to the top right.
The \e[2J prints a space over all existing screen characters.
It is necessary to do it 1;1H and then 2J.
Comments
: how do i implement the dos command 'cls' in my c program.
: yes, i am a newbie.
:
system("cls");
: : how do i implement the dos command 'cls' in my c program.
: : yes, i am a newbie.
: :
:
: system("cls");
:
:
[code]
#include
system("cls");
[/code]
:-)
or with scrclr(); in conio.h
: or with scrclr(); in conio.h
:
:
that is non-anscii c so not all compilers will have that function.
Correct :-)
What is the difference between get char( );
get che ( );
get ch( ) ;
and get s();
getchar() takes one character
getche() would also take one character but would not display it on the screen
getch() is similar to getchar except that it is in conio.h
gets() would take a whole string and store it in a character array
It's a simple question, but there's no easy answer.
The core C language doesn't have a concept of screens. It has standard input ans standard output, which these days are almost always connected to DOS boxes or Unix terminals, but historically were often teletypes. So it sees output as a series of characters.
But the computer sees the DOS or Unix terminal as a program in its own right, and can treat it as an N x M raster of characters. conio.h or curses.h (for DOS or Unix) contain functions that do that.
Another answer, which has already been given, is to issue the system cls comand.
Another answer is that Ascii 0x0B, or form feed, will often be honoured, and move the terminal to a fresh screen.
You can also print lots of newlines
There is a very easy answer and here it is:
printf("\e[1;1H\e[2J");
or if you're like me and don't have any printf or stdio:
write(0,"\e[1;1H\e[2J",12);
--INFO--
The \e[1;1H sets your cursor to the top right.
The \e[2J prints a space over all existing screen characters.
It is necessary to do it 1;1H and then 2J.