dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Beginner
Feb 3, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Problems with Getc and Scanf

Question:
I want to make a menu, where you can select from 1-4. By pressing one of these keys you should get into a subprogram. Now I have to press enter after I select 1,2,3 or 4. Is it possible to have C++ bypass "enter" and go directly to the subprogram. I can't see how I can use getc or scanf, but are there any other possibilities or functions I could use?

Answer:
Instead of scanf(), use the getche() function which is defined in . For example:

#include 
#include 
int main()
{
 char userdata;
 printf("enter your choice: ");
 userdata = getche(); // "Enter" not needed
} 
Editor's Note: This answer has been changed from the original.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date