C/C++ code

Sharky Forums


Results 1 to 5 of 5

Thread: C/C++ code

  1. #1
    Sushi SirGuga's Avatar
    Join Date
    Apr 2001
    Location
    Santiago,Rm,Chile
    Posts
    2

    Question C/C++ code

    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......

  2. #2
    Expensive Sushi
    Join Date
    Mar 2001
    Location
    Mt. Airy, NC, US
    Posts
    37

    Post

    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
    -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

  3. #3
    Catfish
    Join Date
    Sep 2000
    Location
    bc
    Posts
    185

    Post

    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...!!
    Help!!! I'm swimming with the sharks...!!

  4. #4
    Hammerhead Shark
    Join Date
    Oct 2000
    Location
    Toronto, Canada
    Posts
    1,493

    Post

    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.
    DHAHL3seasons GP:73 G:121 A:55 Pts:176 GWG:12 +/-:184
    UWSWA6seasons GP:41 G:53 A:46 Pts:99 GWG:5 +/-:-25
    MCBHL3seasons GP:14 G:20 A:8 Pts:28 GWG:4 +/-:19

    uwcdc.com or monkis.com

  5. #5
    Hammerhead Shark Racer^'s Avatar
    Join Date
    Feb 2001
    Posts
    1,758

    Post

    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
    Primary:
    Shuttle SN41G2 (nForce2) 333 FSB sync. /
    Barton 2500 w/ 2 x 512MB PC2700 DC-DDR /
    GeForce 4 4400 / Seagate Bara-V 80 GB /
    Envision 980e 19" + ViewSonic 15" / Windows XP SP1 /
    http://service.futuremark.com/compare?2k1=6388169

    Secondary:
    ABit KT7 (YH) VIA 4.29 /
    TBird 864 (oc 108 x 8) / 256 MB PC133 /
    TNT2 / 40GB 5T040H4 / ESS 1869 /
    NetGear FA311 10/100 NIC /
    Win2k Pro SP3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •