home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1330 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: erc@khijol.UUCP (Ed Carp, aka Mr. Ed the talking horse...)
  2. Newsgroups: alt.sources
  3. Subject: addtimes - add a list of times in XX:YY form
  4. Message-ID: <1425@khijol.UUCP>
  5. Date: 9 May 90 03:51:43 GMT
  6.  
  7.  
  8. /*
  9. *
  10. * This little hack will add times and give you the total.  It's handy for
  11. * mixing songs when re-recording a tape, and you want to make sure that the
  12. * songs all fit on the tape.
  13. *
  14. * usage: times time time time ...
  15. *
  16. * times must be in the form XX:YY
  17. *
  18. * Written 04/29/90 by Edwin R. Carp (erc@khijol.UUCP) at 2:30 AM, so don't
  19. * fuss at me for the lack of docs!  You can use this for anything you want -
  20. * it's free.  If you can make money off of this, hey - more power to you!
  21. *
  22. */
  23.  
  24. #ifndef NULL
  25. #define NULL 0
  26. #endif
  27.  
  28. #ifdef BSD
  29. #define strchr index
  30. #endif
  31.  
  32. main(argc, argv)
  33. int argc;
  34. char **argv;
  35. {
  36.    float frac, total, atof();
  37.    int i, min;
  38.    char *ptr, *strchr();
  39.  
  40.    if(argc < 2)
  41.    {
  42.       printf("usage: %s time(s)\n", argv[0]);
  43.       exit(1);
  44.    }
  45.    total = 0.0;
  46.    for(i=1; i<argc; i++)
  47.    {
  48.       /* split up times into mm:ss */
  49.       if((ptr=strchr(argv[i], ':')) == (char *)NULL)
  50.          frac = 0.0;
  51.       else
  52.       {
  53.          if(strlen(ptr+1) != 2)
  54.          {
  55.             printf("error: '%s': bad time (must be XX:YY)\n", argv[i]);
  56.             exit(1);
  57.          }
  58.          frac = atof(ptr+1);
  59.          frac = frac / 60.0;
  60.       }
  61.       frac += atof(argv[i]);
  62.       /* frac now contains mm.ss */
  63.       total += frac;
  64.    }
  65.    printf("%d:", (int)total);
  66.    /* now convert the fractional part back into 60ths */
  67.    total = total - (float)((int)total);
  68.    total = total * 60.0;
  69.    printf("%02d\n", (int)(total+0.5));
  70. }
  71. --
  72. Ed Carp - N7EKG/5        (415) 769-5400  [work]               asylum!khijol!erc
  73.  
  74. "Let's find a little house in a valley, where the sun's always smiling,
  75. The perfect place for you and me -- miles away."  -- Basia
  76. -- 
  77. Ed Carp - N7EKG/5        (415) 769-5400  [work]               asylum!khijol!erc
  78.  
  79. "Let's find a little house in a valley, where the sun's always smiling,
  80. The perfect place for you and me -- miles away."  -- Basia
  81.