Guest User

Sleep Countdown

a guest
Jan 12th, 2012
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifdef _WIN32
  4.   #include <io.h>
  5.   #include <dos.h>
  6.   #include <windows.h>
  7. #endif
  8. #ifdef __unix__
  9.   #include <unistd.h>
  10.   #include <time.h>
  11. #endif
  12. int SecondsToSleep;
  13. int SecondsLeft;
  14. int ShowHelp;
  15. int main(int argc, char* argv[]){
  16.   if(argc == 1){
  17.     ShowHelp = 1;
  18.   }else{
  19.     SecondsLeft = atoi(argv[1]);
  20.     if(SecondsLeft == 0){
  21.       ShowHelp = 1;
  22.     }else{
  23.       printf("Counting down... ");
  24.       fflush(stdout);
  25.       while(SecondsLeft > 0){
  26.         printf("%i.. ", SecondsLeft);
  27.         fflush(stdout);
  28.         #ifdef _WIN32
  29.           Sleep(1000);
  30.         #endif
  31.         #ifdef __unix__
  32.           sleep(1);
  33.         #endif
  34.         SecondsLeft = SecondsLeft - 1;
  35.       }
  36.       printf("\n");
  37.     }
  38.   }
  39.   if(ShowHelp == 1){
  40.     printf("Sleep Countdown v1.1 - Jaap-willem Dooge\n\n");
  41.     printf(" SleepCD <seconds>\n\n");
  42.     fflush(stdout);
  43.   }
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment