LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2003, 03:23 PM   #1
Patchorus
LQ Newbie
 
Registered: Aug 2003
Location: Sweden
Distribution: Fedora core 4
Posts: 25

Rep: Reputation: 15
just a little question about c++


i just wonder if anyone could tell me what i type in c++ so if i press a button in my program i tell it to do different stuff. for example "Q" i quit the program and if i press "s" i do something else. and so on...

have looked through some helpsites but i cant find just this part.

Last edited by Patchorus; 08-26-2003 at 03:24 PM.
 
Old 08-26-2003, 08:09 PM   #2
jmawebb
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
Lightbulb

I don't think it's easy to do portably. Under Linux, you could use ncurses:

#include <curses.h>

int main()
{
initscr();
cbreak();
noecho();

printw("Test: Hit a key.\n");
char x = getch();
printw("You pressed '%c'.\nHit another key.\n", x);
getch();

endwin();
}

Compile with:
g++ -otest test.cc -lcurses

-- Jamie Webb
 
Old 08-27-2003, 06:20 AM   #3
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
Well , you can also just get the input as a char and compare it using case statements and then execute the results.

For example,
char ch;
printf("Enter the char :");
scanf("%c",&ch);// ( I generally use C++ & am not sure if this correct)
switch(ch):
case c:
// Do something
case q:
// Quit
default:
exit(0);

I think this is just a sample and you have to develop from here. And I hope that this is what you have been looking for...
 
Old 08-27-2003, 08:34 AM   #4
Patchorus
LQ Newbie
 
Registered: Aug 2003
Location: Sweden
Distribution: Fedora core 4
Posts: 25

Original Poster
Rep: Reputation: 15
thanks. ill test it right away
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 03:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration