15 Replies - 7290 Views - Last Post: 22 May 2010 - 07:06 AM
#1
Single Character Input
Posted 20 May 2010 - 02:28 AM
i m searching for a method by wich i can take a character input without using conio.h
(getche())
and with out pressing enter at end
a function which is exactly similar to getche() of conio.h
(getche())
and with out pressing enter at end
a function which is exactly similar to getche() of conio.h
Replies To: Single Character Input
#2
Re: Single Character Input
Posted 20 May 2010 - 02:33 AM
Why don't you use getchar() ?
That will echo the keyboard input back to the user.
char ch;
while( (ch = getchar()) != EOF ){
putchar(ch);
}
That will echo the keyboard input back to the user.
#4
Re: Single Character Input
Posted 21 May 2010 - 01:28 PM
sarmanu, on 20 May 2010 - 01:34 AM, said:
Will this help you?
gtchar() requires enter key to be pressed after entering any character
i want take single character input from console
for example here is sample out put
Enter Your choice : (here user should press only one key)
Your required informations are : ...
program should not wait for enter key ('\n')
#5
Re: Single Character Input
Posted 21 May 2010 - 02:34 PM
if your on windows you could use the getch() function in conio.h
#6
Re: Single Character Input
Posted 21 May 2010 - 09:30 PM
i dont want use conio.h
any alternate method
#7
Re: Single Character Input
Posted 21 May 2010 - 09:35 PM
Did you look at the snippet sarmanu gave you at post #3?
If not then have a look at it.
If you did then what about it was not what you wanted?
If not then have a look at it.
If you did then what about it was not what you wanted?
#8
Re: Single Character Input
Posted 21 May 2010 - 09:37 PM
Muhammad.Arif, on 22 May 2010 - 09:00 AM, said:
i dont want use conio.h
any alternate method
You should have a look here:
http://www.cplusplus...am/istream/get/
Hope it helps!
#9
Re: Single Character Input
Posted 21 May 2010 - 09:37 PM
#10
Re: Single Character Input
Posted 21 May 2010 - 09:46 PM
Muhammad.Arif, on 22 May 2010 - 01:37 PM, said:
i could not underestand loops condition while( (ch = getchar()) != EOF ) when will loop terminate
That loop, as written, will never terminate.
If you wanted to break out of the loop when certain conditions are met then I suspect you have all the coding skills and knowledge to write code to achieve that.
Perhaps an if() test?
Perhaps a break statement?
This post has been edited by janotte: 21 May 2010 - 09:54 PM
#11
Re: Single Character Input
Posted 22 May 2010 - 06:11 AM
actually no one understood my problem i have written a program and there are many choices for user to use that program for example user can enter data, view data, delete data etc. from a given record here is some sample output
Press 1 to enter data
Press 2 to view record
Press 3 to delete record
Press 4 to exit program (and so on some other options)
now i want that is when user just press 1 key there should be menu to enter data if user press 2 record should be viewed on screen (and so on)
how can i take input for choice from user without using conio.h
i know that using conio.h i can solve this easily like
char ch = getche();
but i want this without using conio.h as conio.h is not part of standart c++
all functions cin.get(ch) or other forms of this functions require enter key to be pressed at the end
there should no need for user to press enter key
can any one help me
Press 1 to enter data
Press 2 to view record
Press 3 to delete record
Press 4 to exit program (and so on some other options)
now i want that is when user just press 1 key there should be menu to enter data if user press 2 record should be viewed on screen (and so on)
how can i take input for choice from user without using conio.h
i know that using conio.h i can solve this easily like
char ch = getche();
but i want this without using conio.h as conio.h is not part of standart c++
all functions cin.get(ch) or other forms of this functions require enter key to be pressed at the end
there should no need for user to press enter key
can any one help me
#12
Re: Single Character Input
Posted 22 May 2010 - 06:22 AM
#13
Re: Single Character Input
Posted 22 May 2010 - 06:37 AM
i think this link is of .net not c++ i have not learned commands like this
#14
Re: Single Character Input
Posted 22 May 2010 - 06:40 AM
It is C++ in the .NET Framework.
Really read the link.
Since we have to guess at what constraints you are putting on the program you are writing then we have to guess at what answers might be useful to you.
Really read the link.
Since we have to guess at what constraints you are putting on the program you are writing then we have to guess at what answers might be useful to you.
#15
Re: Single Character Input
Posted 22 May 2010 - 06:48 AM
is there any other option?
This post has been edited by Muhammad.Arif: 22 May 2010 - 06:49 AM

New Topic/Question
Reply



MultiQuote




|