Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-04-2003, 06:34 PM   #1 (permalink)
DemosthenesB
Registered User
 
Join Date: Mar 2003
Posts: 7
DemosthenesB is on a distinguished road
Alarm

How can I make a program that keeps time? That counts seconds and displays them as an output? I am trying to make an alarm clock program that after so many seconds opens up a sound file.

I am not experienced with C but I know the basics of "if" and "while" statements(I am fairly experienced with Macromedia's Flash Actionscript). I have made an alarm program in Actionscript but it is very easy to count seconds as you have a timeline and can change the fps, and then it is also easy to open sound files as they can be imported into the file. But in C I don't know how to do these things.

Any suggestions?
DemosthenesB is offline   Reply With Quote
Old 04-04-2003, 08:42 PM   #2 (permalink)
palin
Code Monkey
 
palin's Avatar
 
Join Date: Jan 2003
Posts: 57
palin is on a distinguished road
<time.h> has time functions in it

on Linux/Unix there is a function called
time( time_t* __timer);

if you call it like so time(NULL) it will return the number of seconds since some date in the 70s since I assume you only wish to use the actual time elasped between a start point and another point. obviously just get a start value then you can compare it with repeated calls.

Hope this helps.
palin is offline   Reply With Quote
Old 04-05-2003, 03:10 PM   #3 (permalink)
DemosthenesB
Registered User
 
Join Date: Mar 2003
Posts: 7
DemosthenesB is on a distinguished road
Thank you very much palin, very helpful.
DemosthenesB is offline   Reply With Quote
Old 05-05-2003, 12:53 AM   #4 (permalink)
ender
Code Monkey
 
ender's Avatar
 
Join Date: Mar 2003
Location: Evansville, IN
Posts: 75
ender is on a distinguished road
Send a message via AIM to ender Send a message via Yahoo to ender
Signals

Another thing you could do, supposing that your OS supports posix signals and such, is use signals to do it, you could set up your own signal handler and use the interval timer functions to set up your interval. That is how I would do it, then you don't have to do repetitive queries to time() or the like.

The signal is called SIGALRM, and the you can use either the alarm() function that works in seconds, or the setitimer() function which can work in microseconds.

Just a suggestion,
Ted Morse
__________________
while(1) fork();
ender is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting