Printing System time and 30 minute alarm

This is a discussion on Printing System time and 30 minute alarm within the C Programming forums, part of the General Programming Boards category; I am trying to figure out how to get C to set an alarm for 30 minutes ahead of whatever ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    Printing System time and 30 minute alarm

    I am trying to figure out how to get C to set an alarm for 30 minutes ahead of whatever the displayed time is. I got the rough draft of displaying the system time (although it does prompt me to input a new system time which im not too fond of) but unsure of what my options are when it comes to the 30 minute alarm timer.

    Here is the system time code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main(void)
    {
    string thirty;
    time_t now;
    time(&now);
    alarm(&thirty)= time + 30;
    printf("%s", ctime(&now));
    printf("%s", alarm(&thirty));
    
    return EXIT_SUCCESS;
    }

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Does that even compile ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    Compile

    It does not compile. It did until I tried to put the thirty statement in there and then kind of got stuck.

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Ok, well now stores the time in seconds. So then calculate how many seconds in 30 minutes.

    Then :
    Code:
    while(time(NULL)  - null < secondsin30mins)
    {
        //  Countdown to 30 minutes
    }
    //  Sound alarm.
    You may want to check this out.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    little confused

    okay so the while statement starts the countdown? how would i get the program to display that the timer was set when the program was run and will go off at time 11:00pm (if program is run at 10:30)

    Kevin

  6. #6
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    The while loop doesn't so much start the countdown as it just counts the seconds that go by. To show what time it started and what time it will finish you would have to use other commands. Look at the link I provided.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    looking at the link

    thanks for the link although I think it might be written a little over my head..

  8. #8
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Work at it. Once you understand it, your program will be a cinch.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Lookup localtime() and mktime()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    question

    It also doesnt seem to really matter what other code I program into it because all my program ends up doing is compiling and then when it is run it tells you the current time and allows input for a new time and then stops running regardless of everything else i have. Even tested it with printf("SAY SOMETHING"); code to no avail.


    Kev

  11. #11
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Then it's time for you to show us some code. And check to see if this is the problem.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    Coding Problems

    here is the code
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main( void )
    {
        time_t t1;                                 
        struct tm *tptr;
        clock_t ticks;                             
        char *s;
    
        if ( ( t1 = time(( time_t * ) 0 )) != ( time_t )-1 ) 
    	{
            s = ctime( &t1 );
            printf( "Current time is %s", s );
            tptr = localtime( &t1 );
            printf( "You have an appointment in 30 minutes at time %d:%d:%d.\n",              
                                           tptr->tm_hour, 
                                           tptr->tm_min+30,
                                           tptr->tm_sec );
           }
        else
            printf( "Error with the time() function\n" );
    
                                                              
        
        return 0;
    }

    Now it compiles just fine but running the program it only displays the current time and than asks the user for the new time. And these words aren't coming from my program. No matter what I have printf say it still says

    The current time is 21:21:06
    Enter new time:
    <USER INPUT>
    and then ends the program.

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    You've called your program "time.exe"
    Which is the same name as an existing command on your system (which is the one you're getting).

    Try perhaps (from the directory where your .exe exists)
    ./time.exe

    This should run your version rather than the system version.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Posts
    23

    that works

    thanks now it works and im trying to figure how to carry over 30 minutes to the next hour
    for example 18:45 30 minutes later it says 18:75 and i want it to read 19:15.

    if statement? not sure where to start.


    kevin

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    The mktime() function sorts out all the rounding necessary following things like
    tptr->tm_min += 30;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  3. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 08:08 PM
  4. time of system
    By arian in forum C++ Programming
    Replies: 3
    Last Post: 12-10-2003, 11:51 AM
  5. Replies: 72
    Last Post: 11-25-2002, 04:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21