473,388 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

C++ using keyboard system inputs

RADAR
21
i use VC++ 6,0 and i have problems with getting keyboard system inputs and to use them to check to proceed or break the loop.
for example if i want to proceed until Ctrl+z is written for input.What will the compiler do?Does it accept Ctrl+Z as a normal string input , char* input, or a char input which has ASCII 26...
suppose i have a loop that does the following:
-first check the choice
-if not Ctlr+Z continue
-else go to the next stage.


"%
i only need when Ctrl+Z is performed using keyboard and it is gotten by select,it should exit the loop..
%"

i tried to do sth:
Expand|Select|Wrap|Line Numbers
  1. char select;
  2. string str;
  3.  
  4. while(select != char(26)) //--char(26) is the ASCII equivalent of Ctrl+Z , i guess
  5. {
  6.              cout     <<" Enter a string";
  7.             cin >>str;
  8.             locate_asterisk(str);//--a function that adds '*' after each char in a cpp          
  9.                                         //--string
  10.             cout       <<"If you want to continue, press any character"
  11.                          <<"or to exit perform Ctrl+Z from keyboard"<<endl;
  12. }
  13.  
by pressing Ctrl+Z some strange characters appear; like ^Z
i was trying this for more than 10 hours but i was really confused on what to do.
I will be very pleased if any helpful ideas are provided by you;
thanks for now
RADAR
Dec 27 '07 #1
7 3400
gpraghuram
1,275 Expert 1GB
i use VC++ 6,0 and i have problems with getting keyboard system inputs and to use them to check to proceed or break the loop.
for example if i want to proceed until Ctrl+z is written for input.What will the compiler do?Does it accept Ctrl+Z as a normal string input , char* input, or a char input which has ASCII 26...
suppose i have a loop that does the following:
-first check the choice
-if not Ctlr+Z continue
-else go to the next stage.


"%
i only need when Ctrl+Z is performed using keyboard and it is gotten by select,it should exit the loop..
%"

i tried to do sth:
Expand|Select|Wrap|Line Numbers
  1. char select;
  2. string str;
  3.  
  4. while(select != char(26)) //--char(26) is the ASCII equivalent of Ctrl+Z , i guess
  5. {
  6.              cout     <<" Enter a string";
  7.             cin >>str;
  8.             locate_asterisk(str);//--a function that adds '*' after each char in a cpp          
  9.                                         //--string
  10.             cout       <<"If you want to continue, press any character"
  11.                          <<"or to exit perform Ctrl+Z from keyboard"<<endl;
  12. }
  13.  
by pressing Ctrl+Z some strange characters appear; like ^Z
i was trying this for more than 10 hours but i was really confused on what to do.
I will be very pleased if any helpful ideas are provided by you;
thanks for now
RADAR
Usually Ctrl+Z generates the SIGHUP signal in Unix and i am sure that you can handle it only with catching the signal.
But i am not sure whether yopu will be able to read it using cin/scanf


Raghuram
Dec 27 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
The crl+Z is the end-of-all-input signal. You must press <enter> to put that in the input buffer. Without it, an inout loop will run forever askign for more input.

Everything you type is echoed to the screen.
Dec 27 '07 #3
RADAR
21
thanks for trying but i still couldn't do it.
i only want if ctrl+z is entered , the while loop will end the program will continue until the return 0; statement as usual.
thanks again guys.
respects,
radar
Dec 28 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Your code sampoe does not work since select is never initialized and you never use it to get data from the keyboard. Try this:
Expand|Select|Wrap|Line Numbers
  1. string str;
  2. cout     <<" Enter a string";
  3.  
  4. while(cin>>str)
  5. {
  6.              locate_asterisk(str);//--a function that adds '*' after each char in a cpp          
  7.                                         //--string
  8.             cout       <<"If you want to continue, enter a string"
  9.                          <<"or to exit perform Ctrl+Z from keyboard"<<endl;
  10. }
  11.  
Dec 29 '07 #5
RADAR
21
thank you very much for your help , this is so clean and strong answer for my question.i wonder if you can only answer one more question , why do i have to initialize the string variable?
Dec 29 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
why do i have to initialize the string variable?
Every variable needs to be initialized otherwise it just contains the random bits in memory where it was allocated. One of the biggest error areas is in using uninitialized variables. C++ constructors are a way to automate this process.
Dec 30 '07 #7
RADAR
21
thank you so much.
that helped me a lot...
Dec 30 '07 #8

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

Similar topics

0
by: Hiroyuki Tanaka | last post by:
Hi All, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to...
6
by: Brian Basquille | last post by:
Hello all. Due to the short time remaining to my project handup for my Air Hockey game, i've abandoned the idea of implementing it over a network. But since the only real way to play Air...
0
by: Srin | last post by:
Hi, I'm in the process of writing a small C# App, in which i have two groupboxes in a form. The form has the KeyPreview property set to true. The groupbox1 contains a set of labels. The second...
0
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool...
18
by: Rose4msm | last post by:
hello can any one please help me i have a test and i need to study the java scripts, i know that i have to use arrays but im still a bit confuse the question is to ask the user how many data items...
3
by: Adrian Luck | last post by:
Hi, Is it possible to send mouse left click signals/inputs and keyboard inputs from a flash application to another program?
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
3
by: bwgames | last post by:
Hi there, I have a script that takes two inputs from the keyboard to change some settings on some equipment. I would usually run this as e.g. ben@srv001:/$ change-settings<enter> new-setting...
2
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
I am trying to find a good example of SendInput. Doing a search on google I found two, one is incomplete and vague from the start and the other I copied the code and tried running it and it was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.