473,508 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ using keyboard system inputs

RADAR
21 New Member
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 3404
gpraghuram
1,275 Recognized Expert Top Contributor
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 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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 New Member
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
2652
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
3156
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
1442
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
2720
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
20425
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
1972
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
6553
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
7309
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
9469
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
7227
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
7127
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...
0
7501
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
5633
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
5056
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
4713
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
3204
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...
0
1564
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 ...
0
424
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.