473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input Question

2 New Member
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
Sep 20 '07 #1
6 1236
pbmods
5,821 Recognized Expert Expert
Heya, Olof. Welcome to TSDN!

I presume you're writing this application in C?
Sep 20 '07 #2
Ekranoplan
2 New Member
Ofcourse, how foolish of me. Its written in C++.
Sep 20 '07 #3
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.
Sep 20 '07 #4
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

Expand|Select|Wrap|Line Numbers
  1. string s_ignoreContentsHere;
  2.  
  3. 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
  4. getline(cin,s_ignoreContentsHere); // probably what I would do
  5. scanf("%s",s_ignoreContentsHere); // you might want to check the buffer on this one, I don't know off the top of my head
  6.  
It just depends on how robust/easy you want to make it.
Sep 21 '07 #5
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.
Sep 21 '07 #6
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!
Sep 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
28583
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...
2
1375
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.
6
2902
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...
5
1316
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) {
30
10893
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...
1
1797
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...
5
1391
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...
2
1667
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...
12
2064
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...
0
7199
marktang
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,...
0
7453
tracyyun
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...
0
5576
agi2029
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,...
1
5005
isladogs
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...
0
4670
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...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
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 ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.