Thread: Reading and processing input from keyboard

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    30

    Reading and processing input from keyboard

    Hi,

    I have some questions about how to work with input from the keyboard. This code can read characters from the keyboard and print them:

    Code:
    #include <stdio.h>
    
    main()
    {
    	int c;
    
    	c = getchar();
    
    	while(c != EOF)
    		{
    		putchar(c);
    		c = getchar();
    		}
    
    	return 0;
    }
    However, how can I make so that the input isn't displayed to the screen and is also limited to one character each time (so that you don't have to press RETURN) ? Basically what I want is to make a switch statement based on a few characters read from the keyboard.

    Thanks in advance.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading from an input file + processing
    By Mooncow in forum C Programming
    Replies: 2
    Last Post: 12-01-2008, 02:45 AM
  2. Reading in 16 and 24-bit audio data into (32-bit) integer buffers
    By theblindwatchma in forum C Programming
    Replies: 2
    Last Post: 04-13-2008, 11:12 PM
  3. Reading 1D data into 2D array
    By ulillillia in forum C Programming
    Replies: 4
    Last Post: 07-06-2007, 02:11 PM
  4. reading a text file printing line number
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-16-2005, 10:31 AM
  5. Reading the input file into integer arrays
    By supaben34 in forum C++ Programming
    Replies: 3
    Last Post: 12-06-2002, 07:04 PM