I have a program that implements Conway's Game of Life. I want it to execute one iteration everytime the user hits the 'enter' key on the keyboard. How would I handle that input?
Regards,
Olof
6 1236 pbmods 5,821
Recognized Expert Expert
Heya, Olof. Welcome to TSDN!
I presume you're writing this application in C?
Ofcourse, how foolish of me. Its written in C++.
pbmods 5,821
Recognized Expert Expert
Heya, Ekranoplan.
I'm going to go ahead and move this thread to the C++ forum, where our resident Experts will be better able to help you out.
sicarie 4,677
Recognized Expert Moderator Specialist
If you're just trying to get an "Enter" (aka \n char), you can use any input method, and discard what is read in. For example -
string s_ignoreContentsHere;
-
-
cin >> s_ignoreContentsHere; // Though this can fill up your input buffer as it stops at whitespace, and will then try to 'refill' as soon as the first part has been read
-
getline(cin,s_ignoreContentsHere); // probably what I would do
-
scanf("%s",s_ignoreContentsHere); // you might want to check the buffer on this one, I don't know off the top of my head
-
It just depends on how robust/easy you want to make it.
Ganon11 3,652
Recognized Expert Specialist
The problem you'll face there is that the computer will be waiting for the user to type in something other than <enter>, so if the user simply presses enter, it will think it's still retrieving input and not continue with the program's execution. Try cin.get(), which will take the next character entered no matter what - now you can simply press enter to continue.
sicarie 4,677
Recognized Expert Moderator Specialist
The problem you'll face there is that the computer will be waiting for the user to type in something other than <enter>, so if the user simply presses enter, it will think it's still retrieving input and not continue with the program's execution. Try cin.get(), which will take the next character entered no matter what - now you can simply press enter to continue.
/sicarie actually does programming
Dang. Thanks for catching that, Ganon11!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Doug Lowe |
last post by:
In Java 1.5, what's the easiest way to get a console java app to stop until
the user presses the Enter key?
I want to do something like this:
Scanner sc = new Scanner(System.in);
String...
|
by: Gonzosez |
last post by:
How can I limit the quantity of characters in an input box
I need to limit the input to 10 for example.
|
by: a |
last post by:
(I've reached that familiar place where I've got a nagging little
problem in a program I'm writing but I've been staring at code for too
long and I probably wouldn't be able to recognize the answer...
|
by: cjl |
last post by:
Hey all:
I have the following html and javascript:
HTML:
<form name="searchme" action="" onKeyPress="checkSection('searchme');">
JAVASCRIPT:
function checkSection(submitter)
{
|
by: Richard |
last post by:
Level: Java newbie, C experienced
Platform: Linux and Win32, Intel
Another programmer and I are working on a small project together.
He's writing a server process in Java that accepts input...
| |
by: cbbibleboy |
last post by:
Howdy!
I'm importing a large file (213 MB) and parsing it. My question is: does the VB6 Line Input read the whole file, then select out each line, or actually only read that line. I thought it...
|
by: theflyingminstrel |
last post by:
Hi I have a question, it's probably very basic but I'm still learning the Javascript basics.
The following form outputs a string change (from "input" to "text" box ). When the word "test" is...
|
by: tbrogdon |
last post by:
I have a form to add new employees to tblEmployee with the following
fields:
Department (text - linked to tblDept - 3 values in a single field)
Shift (numeric - linked to tblShift - 3 values in...
|
by: Tarique |
last post by:
I have tried to restrict the no. of columns in a line oriented user
input.Can anyone please point out
potential flaws in this method?
btw..
1.I have not used dynamic memory allocation because...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |