home *** CD-ROM | disk | FTP | other *** search
- From: erc@khijol.UUCP (Ed Carp, aka Mr. Ed the talking horse...)
- Newsgroups: alt.sources
- Subject: addtimes - add a list of times in XX:YY form
- Message-ID: <1425@khijol.UUCP>
- Date: 9 May 90 03:51:43 GMT
-
-
- /*
- *
- * This little hack will add times and give you the total. It's handy for
- * mixing songs when re-recording a tape, and you want to make sure that the
- * songs all fit on the tape.
- *
- * usage: times time time time ...
- *
- * times must be in the form XX:YY
- *
- * Written 04/29/90 by Edwin R. Carp (erc@khijol.UUCP) at 2:30 AM, so don't
- * fuss at me for the lack of docs! You can use this for anything you want -
- * it's free. If you can make money off of this, hey - more power to you!
- *
- */
-
- #ifndef NULL
- #define NULL 0
- #endif
-
- #ifdef BSD
- #define strchr index
- #endif
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- float frac, total, atof();
- int i, min;
- char *ptr, *strchr();
-
- if(argc < 2)
- {
- printf("usage: %s time(s)\n", argv[0]);
- exit(1);
- }
- total = 0.0;
- for(i=1; i<argc; i++)
- {
- /* split up times into mm:ss */
- if((ptr=strchr(argv[i], ':')) == (char *)NULL)
- frac = 0.0;
- else
- {
- if(strlen(ptr+1) != 2)
- {
- printf("error: '%s': bad time (must be XX:YY)\n", argv[i]);
- exit(1);
- }
- frac = atof(ptr+1);
- frac = frac / 60.0;
- }
- frac += atof(argv[i]);
- /* frac now contains mm.ss */
- total += frac;
- }
- printf("%d:", (int)total);
- /* now convert the fractional part back into 60ths */
- total = total - (float)((int)total);
- total = total * 60.0;
- printf("%02d\n", (int)(total+0.5));
- }
- --
- Ed Carp - N7EKG/5 (415) 769-5400 [work] asylum!khijol!erc
-
- "Let's find a little house in a valley, where the sun's always smiling,
- The perfect place for you and me -- miles away." -- Basia
- --
- Ed Carp - N7EKG/5 (415) 769-5400 [work] asylum!khijol!erc
-
- "Let's find a little house in a valley, where the sun's always smiling,
- The perfect place for you and me -- miles away." -- Basia
-