Thread: This program makes my computer SLOW

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    This program makes my computer SLOW

    This program is an alarm clock you enter a date and time and it will tell you when its that time. The only problem is that it keeps having to get the time which makes it impossible to run any other big programs (which I won't to do) So can someone please help me make it more PC friendly

    Code:
    #include<time.h>
    #include<stdio.h>
    
    int main(void)
    {
    char hello[100], user[100];
    int f;
      time_t timer;
      timer=time(NULL);
      strcpy(hello,asctime(localtime(&timer)));
      timer=time(NULL);
      printf("%s", &hello);
      fgets(user, 100, stdin);
      printf("%s", user);
      
      
      while (f!=3)
      {
      strcpy(hello,asctime(localtime(&timer)));
      if (strncasecmp(hello, user, 100) == 0)
      {
      printf("\n\n\t\t\tYES");
      f=3;
      }
      timer=time(NULL);
      }
      
      return 0;
    }
    OS:- XP
    Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    also

    Also how do I check to see if the time and date has already pasted.
    OS:- XP
    Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    Unhappy I tryed

    I tryed but it doesn't work heres my code...
    Code:
    #include<windows.h>
    #include<time.h>
    #include<stdio.h>
    
    int main(void)
    {
    char hello[100], user[100];
    int f, elapsed;
      time_t timer;
      timer=time(NULL);
      strcpy(hello,asctime(localtime(&timer)));
      timer=time(NULL);
      
      printf("%s", &hello);
      fgets(user, 100, stdin);
      printf("The timer is primed and shall alert you when your entered time has been reached\nDO NOT EXIT otherwise timer shall stop(run in the background)\n");
      
    
      while (f!=3)
      {
      strcpy(hello,asctime(localtime(&timer)));
      
      if (strncasecmp(hello, user, 100) == 0)
      {
      MessageBox(NULL, "BEEP BEEP!", "BEEP!", MB_OK);
      f=3;
      }
      elapsed = difftime(hello, user);
      if (elapsed < 0)
      {
      printf("Yes");
      f=3;
      }
      timer=time(NULL);
      sleep (100);
      }
      MessageBox(NULL, "Thank you for using DG's alarm clock I hope it was usful\n\thttp://members.aol.com/dg1234uk", "DG's Alarm Clock!", MB_OK);
      return 0;
    }
    OS:- XP
    Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    Question Sorry

    Well how do I put the users input into a time(and not a string)? So I can use difftime?

    (My compiler didn't come up with any errors!)
    OS:- XP
    Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Here's my stab
    Code:
    #include <stdio.h>
    #include <time.h>
    #include <unistd.h>     // sleep()
    
    void wait_for_alarm ( time_t alarm ) {
        time_t  now = time(NULL);
        while ( difftime(alarm,now) > 0 ) {
            sleep( 1 );
            now = time(NULL);
        }
        printf( "Alarm!!!\n" );
    }
    
    int main ( ) {
        time_t      now, alarm;
        char        buff[BUFSIZ];
        struct tm   tm = { 0 };
    
        printf( "Enter time in yyyy/mm/dd hh:mm:ss format > " );
        fflush( stdout );
        if ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
            int yr, mon, day, hr, min, sec;
            if ( sscanf( buff, "%d/%d/%d %d:%d:%d",
                         &yr, &mon, &day, &hr, &min, &sec ) == 6 ) {
                tm.tm_sec = sec;
                tm.tm_min = min;
                tm.tm_hour= hr;
                tm.tm_mday= day;
                tm.tm_mon = mon-1;
                tm.tm_year= yr-1900;
                alarm = mktime( &tm );
                now = time( NULL );
                if ( difftime(alarm,now) < 0 ) {
                    printf( "Alarm time passed\n" );
                } else {
                    wait_for_alarm( alarm );
                }
            }
        }
        return 0;
    }
    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.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Here I wrote this quick hack. It has one downside, you have to CTRL+ALT+DEL to get rid of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  2. Unlocking my computer
    By LuckY in forum Tech Board
    Replies: 20
    Last Post: 03-31-2004, 01:28 PM
  3. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 08:04 AM
  4. strcat makes program crash
    By imoy in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2002, 02:41 PM
  5. hOW TO MAKE A PROGRAM WHICH MAKES MY pC TO SHUTDOWN?
    By ALANAIR23 in forum Windows Programming
    Replies: 9
    Last Post: 09-01-2001, 01:27 AM