May 2021 2 83 Report
C programming; "DOS" shell under Windows 7?

I'm using Microsoft Visual Studio 2010 and programming in C. The computer is running Windows 7. The program I'm writing will run in a cmd window (C:\Windows\system32\cmd.exe).

The program has a char variable, "foo." What I need the program to do is:

1) set foo to some default value, let's say "D"

2) Prompt the user to enter the value of foo. It should not be necessary for the user to follow the entry with the "Enter" key (e.g., if the user hits only the "a" key, then foo becomes "a"). If the user makes no entry at all for five seconds, keep the default value for foo and go to step 3. If the user enters a character, immediately go to step 3 (i.e., don't wait out the remainder of the five seconds.)

3) report back the value of foo to the user -- printf("Foo is %c\n",foo);

My compiler, MS Visual Studio 2010, will do C++ as well, and I'm aware that C++ is (in theory at least) a superset of C. I only know some C programming, not C++, so if you give me a C++ answer please keep in mind that it will have to work with a program that's otherwise in C.

How do I do this? Thanks!

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments

Helpful Social

Copyright © 2024 Q2A.MX - All rights reserved.