Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: Kintaro on 8 November 2002, 15:53

Title: C Q
Post by: Kintaro on 8 November 2002, 15:53
I have a question for C/C++

Whats a damn function that can be used like a variable for key input

For example in basic there is the INKEY$ variable which always is the current key being used... Whats the C/C++ equiv?
Title: C Q
Post by: jtpenrod on 9 November 2002, 01:31
quote:
What's a damn functionthat can be used like a variable for key input
Try this damn function:
Code: [Select]
_______________________________________
Live Free or Die: Linux
(http://www.otakupc.com/etsig/dolphin.gif)
Their fundamental design flaws are completely concealed by their superficail design flaws.
Title: C Q
Post by: Kintaro on 9 November 2002, 14:54
Thank-you ill try that damn function!
Title: C Q
Post by: Kintaro on 9 November 2002, 15:19
Oh sorry i ment C++

This didnt work:
Code: [Select]
Title: C Q
Post by: choasforages on 9 November 2002, 17:04
errr i can try/*havn't tested this though*/


Code: [Select]

that should do it. ill test it though

[ November 09, 2002: Message edited by: choasforages ]

Title: C Q
Post by: choasforages on 9 November 2002, 17:10
and it does work.
Title: C Q
Post by: Kintaro on 9 November 2002, 17:22
Yes but i want it to do other things until a key is pressed in the loop, then it will interupt it.
Title: C Q
Post by: choasforages on 9 November 2002, 17:34
errr, now your making me think. what kind of things and for your previose example
try tacking this on the includes section

Code: [Select]
Title: C Q
Post by: Kintaro on 9 November 2002, 18:14
Still wont work

wheres god/voidmain when you need him
Title: C Q
Post by: choasforages on 9 November 2002, 18:44
hahah, see if this solves your problem, but you still have to hit enter. im working on it

Code: [Select]

just rember to tell g++
-lpthreads

im looking into unbuffered streams
Title: C Q
Post by: Kintaro on 9 November 2002, 19:01
it seems to have given me this
 
quote:

[X11@X11 X11]$ vi blah.cpp
[X11@X11 X11]$ gcc -o blah blah.cpp
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
                 from blah.cpp:1:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using
one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccXRbBiD.o: In function `main':
/tmp/ccXRbBiD.o(.text+0x63): undefined reference to `std::cout'
/tmp/ccXRbBiD.o(.text+0x68): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std: :o perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccXRbBiD.o(.text+0x83): undefined reference to `std::cout'
/tmp/ccXRbBiD.o(.text+0x88): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std: :o perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccXRbBiD.o(.text+0x98): undefined reference to `std::cout'
/tmp/ccXRbBiD.o(.text+0x9d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std: :o perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccXRbBiD.o(.text+0xaf): undefined reference to `std::cout'
/tmp/ccXRbBiD.o(.text+0xb4): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std: :o perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccXRbBiD.o: In function `__static_initialization_and_destruction_0(int, int)':
/tmp/ccXRbBiD.o(.text+0xe0): undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccXRbBiD.o: In function `__tcf_0':
/tmp/ccXRbBiD.o(.text+0x10f): undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccXRbBiD.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status



[ November 09, 2002: Message edited by: Calum & his insidious little spies ]

Title: C Q
Post by: choasforages on 9 November 2002, 19:16
type g++ instead of gcc
it goes like this

g++ -o  blah blah.cpp -lpthreads

[ November 09, 2002: Message edited by: choasforages ]

Title: C Q
Post by: choasforages on 9 November 2002, 22:00
hehehe, got it to work but its probably not that portable, and i used a little bit of help with the usage of ioctl's. if you were to use only ncurses, it would probably end up being better ill try it later but here is that exakmple that works.

compile it with
g++ -o blah blah.cpp -lpthreads

Code: [Select]
Title: C Q
Post by: Kintaro on 10 November 2002, 21:36
Its still not working   :(  

Heres the error output:
 
quote:

[X11@X11 X11]$ g++ -o blah blah.cpp -lpthreads
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
                 from blah.cpp:1:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using
one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/usr/bin/ld: cannot find -lpthreads
collect2: ld returned 1 exit status



[ November 10, 2002: Message edited by: Ex Eleven / b0b 2.1 ]

Title: C Q
Post by: choasforages on 10 November 2002, 20:37
ooops, i feel stupid its

g++ -o blah blah.cpp -lpthread

extra s on the -lpthread was fooking it up
Title: C Q
Post by: Kintaro on 13 November 2002, 11:22
Cool it works, but is there a more simple way?

I dont exactly need a thread just a variable that tells me the value of the key being pressed for example:

Code: [Select]

Do you get what i mean?
Title: C Q
Post by: smokey on 13 November 2002, 16:13
Code: [Select]

Do you get what i mean?[/qb]<hr></blockquote>

How about this
Code: [Select]

My code isn't the neatest or the greatest and you could probably remove the keypress() function but otherwise it might work. I havent tested it.

[ November 13, 2002: Message edited by: smokey mcp0t / b0b ]

[ November 13, 2002: Message edited by: smokey mcp0t / b0b ]