Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-20-2010, 10:53 PM   #1
Registered: Dec 2008
Location: CH/IL
Distribution: Slackware 13.1 Fedora 12
Posts: 73

Rep: Reputation: 16
input complications

Hello everyone,

I am writing a snake program for my programming class in C. I was thinking about how to implement input from user but i have some difficulties. When the game starts i want to wait 1 second for the user to enter an arrow key ( for the direction ) , if he doesnt enter anything just continue.

I cant use scanf, getchar because they block. I tried using select to keep an eye on stdin but they dont trigger unless a character is followed by the return key.

I know by working with the shell that characters get buffered if they dont appear on the screen ( lets say if u got a search going on and start pressing buttons ). So is there a buffer for those characters, if so could you point me to a text that explains how to deal with it ?

Can you guys plz help me ?
Thank you very much in advance.
Old 11-21-2010, 04:45 AM   #2
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
Have you tried using fgetc ?
Old 11-21-2010, 10:56 AM   #3
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,307

Rep: Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485
You'll probably want to look at ncurses for this.
Old 11-21-2010, 07:35 PM   #4
Registered: Dec 2008
Location: CH/IL
Distribution: Slackware 13.1 Fedora 12
Posts: 73

Original Poster
Rep: Reputation: 16
hey mate i would use fgetc but that call blocks as well ...
Im taking a look at the ncurses wrapper right now . Thanks a lot for the replies

Last edited by chymeira; 11-21-2010 at 08:49 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
complications of copying system leftty Linux - Software 4 10-28-2009 03:08 PM
BCM43xx Complications pauldontknow Linux - Wireless Networking 1 03-06-2008 08:17 PM
dhcpcd wifi: non-stop complications yocompia Linux - Wireless Networking 5 03-02-2004 12:33 PM
X & kernel complications oneandoneis2 Slackware 4 01-04-2004 07:04 AM
Removing LILO: Complications datarella Linux - Newbie 5 09-30-2003 10:20 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:56 PM.

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