stop input form showing on the screen

This is a discussion on stop input form showing on the screen within the C Programming forums, part of the General Programming Boards category; i want to scan in a char y or n. i use scanf("%c",&ans); when i press y or n the ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    17

    Question stop input form showing on the screen

    i want to scan in a char y or n.
    i use scanf("%c",&ans); when i press y or n the y on n shows up on the screen. is there any way to scan in the char without displaying what was pressed.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    A nonstandard function called getch() does this, what platform are you using?

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    17
    i am using microsoft visual c++ to compile and i want to run it in dos

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by the_head
    i am using microsoft visual c++ to compile and i want to run it in dos
    You do realize that MSVC++ comes with a handy set of CDs called the MSDN that have tons of information in them, right?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i am using microsoft visual c++
    Then you have getch, include <conio.h>.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    17
    i dont have the cds
    When i find myself in times of trouble. mother mary comes to me, speaking words of wisdom, let it be C

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by the_head
    i dont have the cds
    I guess you should actually buy your copy next time.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    You dont need the cd's!

    Here is a program with comments to help you get started and you can also go to msdn online for more help too. type it in the search engine google, some people are just not as courteous as others.
    hope this helps you.
    cj
    [code]
    /*
    /* Program: Counting words
    */

    #include<stdio.h>
    #include<ctype.h>

    int found_next_word(void);

    int main(void)
    {
    int word_count = 0; /* initilizes the count to 0 */
    while (found_next_word() == 1) /*detects a word as long as 1 has been returned*/
    ++word_count; /*increases word count if aword has been detected*/
    printf("Number of words = %d\n\n", word_count);
    int found_next_word(); /* fct call */
    return 0; /*program completed successfully*/
    }

    int found_next_word(void) /* fct definition */
    {
    int c;

    while (isspace(c = getchar())) /*reads a character from the keyborad
    and as long as charcter is not a white space,
    the body of the while loop is executed */
    ; /*skip white space */
    if (c != EOF) { /*found next word */
    while ((c = getchar()) != EOF && !isspace(c))
    ; /*skip all except EOF and white space */
    return 1; /*progran not completed successfully*/
    }
    return 0; /*progran completed successfully*/
    }
    [\code]
    cj

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM
  3. clear the screen in console input
    By enggas in forum Linux Programming
    Replies: 4
    Last Post: 07-23-2002, 12:06 PM
  4. Getting input data fram screen with a function ?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-19-2002, 03:22 AM
  5. Keyboard input without screen output?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2001, 01:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21