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 1242 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 answer;
....
System.out.print("Press Enter to continue...");
answer = sc.next();
|
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 even if I
was staring right at it.)
I'm trying to design a function that reads input from my data file into
(a pair of) arrays. Simple enough? However, each line of the file is
either going to be 4 integers or a character (then a carriage...
|
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 from
processes I've written over a TCP connection. My processes are all
written in C; his are all done in Java. He's new to Java, and I've
never really used it.
My input is basically a stream of 32-bit unsigned integers (e.g., the
| |
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 was the second case, but when I'm reading this file, it stalls like no other. A similar smaller file works, but I'm not sure that it should make any difference. (And STD_PROCESSES.Gen_Rec.Record_Type is just a fixed length string*1000)
Line Input...
|
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 inputted, it changes to "good".
Simple question: If there is no matching string, how would I get the form to just display nothing at all?
Thanks!
<html>
|
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 a single field)
First Name (tblEmployee.FirstName)
LastName (tblEmployee.LastName)
Hiring Status (linked to tblHireStatus - 3 values in a single field)
Hire Date (Date/Time)
|
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 thats not something
i want to implement.
2.I suppose my input line oriented .
3.The maximum columns i need is 80
4.There is an infinite loop in the program :)
5.I have *not* tried to validate the data as yet.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |