Click to See Complete Forum and Search --> : C/C++ code
SirGuga
04-10-2001, 11:27 PM
Iīm making a C/c++ program and need two commands.
1- I need a command to make a cs (Clear Screen) and on what library is it.
2- Need to make an input from the keyboard of a single character. I canīt remember the command to reed this character without having to press enter after the character
Thanks......
Xolution
04-10-2001, 11:47 PM
To clear the screen include stdlib.h and use system("cls") for DOS and system("clear") for UNIX. To read a single character from the keyboard, use getchar(); Here's a sample:
#include <stdio.h>
#include <stdlib.h>
main() {
char inputchar;
printf("Clear screen? ");
inputchar = getchar();
if(inputchar == 'y') {
system("cls"); // system("clear") for UNIX
printf("You cleared the screen\n");
} else
printf("You didn't clear the screen\n");
return 0;
}
------------------
-Xolution
"He who fights monsters must look into it that he himself does not become a monster. For when you stare long into the abyss, the abyss stares into you." -Nietzsche
grim_fandango
04-11-2001, 05:19 AM
1. i use clrscr() in conio.h (i think)
2. i use :
#include<iostream.h>
Char varname; // declare it as a character
cout << "Please input something: ";
cin >> varname; //prompt to user to input something
------------------
Help!!! I'm swimming with the sharks...!!
namgor
04-11-2001, 08:12 AM
Originally posted by grim_fandango:
1. i use clrscr() in conio.h (i think)
2. i use :
#include<iostream.h>
Char varname; // declare it as a character
cout << "Please input something: ";
cin >> varname; //prompt to user to input something
both correct!
------------------
I am crab, scoins is crap.
Racer^
04-11-2001, 03:29 PM
FYI: Some conio functions aren't supported by some compilers.
A universal way to clear the screen is to write a whole bunch (50 at most) of '\n' characters to the screen.
------------------
TBird 880 (oc 110 x 8) /
ABit KT7 w/ 256 MB RAM /
TNT2 16MB