just like in a ATM machine if you press a number it will automatically execute that certain function can you hve an example program pls.
In C programming, what is the sintax so that once I press a char or a int a certain task will execute?
let char be an a-%26gt;
char a;
cout%26lt;%26lt;"what you want to perform";
cin%26gt;%26gt;a;
switch (a)
{
case '1':
do your work;
break;
case '2':
do your work;
break;
case '3':
do your work;
break;
}
Reply:/*
You emphesized on Pressing a key and execution of a task
so my answer is same like Usman but with slight modification, which is following
*/
#include %26lt;iostream.h%26gt;
#include %26lt;conio.h%26gt;
void main()
{
char a;
cout%26lt;%26lt;"what you want to perform";
a = getch();
switch (a)
{
case '1':
do your work;
break;
case '2':
do your work;
break;
case '3':
do your work;
break;
}
}
Reply:This depends on which key you want people to press...
If you just want a letter or number to be pressed, then you can use the getch() function.
char ch;
ch=getch();
switch (ch) {
case '1' : /* option 1 was pressed */
perform_option_1();
break
default: invalid_option();
break
}
If you want the user to press one of the non-ascii keys (F1, F2, Esc, PageUp, etc...) then you should use bioskey(), although this needs a little more setting up. I have created a program that uses 'bioskey', and the header file is all done for you, with values for almost any keypress. I've just uploaded to http://cid-7797c171df1b800d.skydrive.liv...
Feel free to download a copy. It comes with an example program to show you how it works.
memory cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment