LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-26-2007, 02:13 PM   #1
mrmz
LQ Newbie
 
Registered: Feb 2007
Posts: 4

Rep: Reputation: 0
doint two things at once in C


i was wandering how to write a program, that would do something (loop around) UNTIL some key is pressed, and if it is pressed, it will do something else.

for example if i wanted to write a countdown timer in C and i wish to have a 'pause' function, but i dont know how to make it to write out the time every couple of ms's and at the same time, if i press a key, to pause the timer
the functions like getchar, scanf etc wait for the user to press the key.. so the coundown timer isnt working at that time

i want something that would do this:


do something
if(key was pressed)
--do sth. else
else
do something again
 
Old 03-26-2007, 03:03 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
This seems to come up a lot, lately. Your question can be rephrased as 'how do I do non-blocking character-at-a-time terminal IO?'. The answer is found in http://www.linuxquestions.org/questi...07#post2570807

--- rod.
 
Old 03-26-2007, 07:27 PM   #3
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
regarding the 'two things at once', you can use multiprocessing and signals. try to find a basic tutorial on it. the system calls would be 'kill', 'signal', and 'fork'.

if this problem isnt an urgent one, i can write an example wednesday or so.. studying for my exam tomorrow!

hope it helps.
 
  


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
Suse: confused on many things, why is installing things so hard? blackflare Linux - Newbie 11 10-16-2007 04:35 AM
LXer: Things found on the way to other things. LXer Syndicated Linux News 0 01-06-2007 08:03 PM
what are these things mean? slazer Slackware 4 12-16-2005 10:19 AM
Need help with a few things.. Please.. sramelyk Linux - Software 8 03-17-2004 02:27 PM
2 things before you go... humanveal Linux - Software 21 08-25-2002 08:41 AM

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

All times are GMT -5. The time now is 11:38 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