Thread: Printing System time and 30 minute alarm

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

    new code new error

    well this is what i got and the code compiles but and gives me the current time and then gives me an error and boots out.

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

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Erm, try reading the manual page?

    time_t
    mktime(struct tm *tm);

    Code:
    time_t now = time(NULL);
    struct tm tnow = localtime( &now );
    tnow.tm_min += 30;
    time_t later = mktime( &tnow );
    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.

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, 12:51 PM
  5. Replies: 72
    Last Post: 11-25-2002, 05:55 PM