Timer trivial

From Tuxunix
Jump to: navigation, search

Exemple d'exécution


Starting...
- -> - -> - ->
              |
              |
              v
<- - <- - <- -
FIRE!!!
   1./*
   2. * timer.c for (self)
   3. *
   4. * Made by tuxedo
   5. *
   6. * Started on Wed 29 Oct 2008 21:01:15 tuxedo
   7. * Last update Wed 29 Oct 2008 21:30:06 root
   8.*/
   9.       
  10./* clock example: countdown */
  11.#include <stdio.h>
  12.#include <time.h>
  13.      
  14.void wait(int seconds){
  15.    clock_t endwait;
  16.    endwait = clock () + seconds * CLOCKS_PER_SEC ;
  17.    while (clock() < endwait) {}
  18.}
  19.       
  20.int main (void){
  21.    printf("Starting...\n");
  22.    system("tput clear");
  23.    printf("- ->\n");
  24.    wait(1);
  25.    system("tput clear");
  26.    printf("\t- ->\n");
  27.    wait(1);
  28.    system("tput clear");
  29.    printf("\t\t- ->\n");
  30.    wait(1);
  31.    system("tput clear");
  32.    printf("\t\t|\n");
  33.    printf("\t\t|\n");
  34.    printf("\t\tv\n");
  35.    wait(1);
  36.    system("tput clear");
  37.    printf("\n\n\n\t\t<- -\n");
  38.    wait(1);
  39.    system("tput clear");
  40.    printf("\n\n\n\t<- -\n");
  41.    wait(1);
  42.    system("tput clear");
  43.    printf("\n\n\n<- -\n");
  44.    wait(1);
  45.    system("tput clear");
  46.    printf("FIRE!!!\n");
  47.       
  48.    return 0;
  49.}