home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / croutes.zip / WEEKDAY.C < prev    next >
Text File  |  1984-04-05  |  2KB  |  41 lines

  1. /*                     *** weekday.c ***                             */
  2. /*                                                                   */
  3. /* IBM - PC microsoft "C"                                            */
  4. /*                                                                   */
  5. /* function to determine the day of the week a given gregorian date  */
  6. /* falls on.  Returns a 0 if successful or a -1 if not.              */
  7. /*                                                                   */
  8. /* WARNING - day must be declared to be at least 10 characters or a  */
  9. /*           memory overwrite will occure.                           */
  10. /*                                                                   */
  11. /* Written by L. Cuthbertson, March 1983                             */
  12. /*                                                                   */
  13. /*********************************************************************/
  14. /*                                                                   */
  15.  
  16. int weekday(indate,day)
  17. char indate[],day[];
  18. {
  19.     static char days [7][10] = {'S','u','n','d','a','y','\0',' ',' ',' ',
  20.                                 'M','o','n','d','a','y','\0',' ',' ',' ',
  21.                                 'T','u','e','s','d','a','y','\0',' ',' ',
  22.                                 'W','e','d','n','e','s','d','a','y','\0',
  23.                                 'T','h','u','r','s','d','a','y','\0',' ',
  24.                                 'F','r','i','d','a','y','\0',' ',' ',' ',
  25.                                 'S','a','t','u','r','d','a','y','\0',' '};
  26.     int iday;
  27.     long julian,gtoj();
  28.  
  29.     /* get julian date */
  30.     if ((julian = gtoj(indate)) == (-1)) return(-1);
  31.  
  32.     /* calculate day of week */
  33.     iday = (julian-1) % 7;
  34.  
  35.     /* move weekday into character string */
  36.     strcpy(day,days[iday]);
  37.  
  38.     /* done */
  39.     return(0);
  40. }
  41.