Thread: plz read

  1. #1
    ######
    Guest

    plz read

    hi im trying to read system date using the int86() function in c...problem is it doesnt display the date it displays numbers that mean nothing in particular......can anyone tell me what i'm doing wrong? thank u

    Code:
    #include <dos.h>
    #include <stdio.h>
    #include <conio.h>
    
    #define DATE 0x2a
    
    int main (void)
    {
      union REGS regs;
      unsigned int cd;
    
          int86(DATE, & regs, & regs);
          clrscr();
     
         cd = regs.h.ah;
    
         printf("date: %d",cd);
         getch();
    
    return 0;
    }

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    I don't know this int86 (?), but assuming it is kinda "placeholder" for BIOS int 01aH, you probably get the values in Binary Coded Digits, e.g. 2003h instead of 2003 decimal.

    So, you probably have to convert the returned values from hex to decimal.

    However, why don't you just use the adequate C functions (gettime, getdate) instead of troubling with int86?

    Or, if you really need ints, use BIOS ints.

    Have fun!
    Last edited by Carlos; 02-03-2003 at 09:05 AM.

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Like Carlos said, you're most likely getting the BCD code. Something like this *might* work provided that you don't want the day of the week too.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
       unsigned char cent, year, month, day;
    
       static char *months[] = 
               { "Error", "January", "February", "March",
                 "April", "May", "June", "July", "August",
                 "September", "October", "November", 
                 "December" };
    
       _asm
       {
          mov ah,0x4
          int 0x1A
          mov cent,ch
          mov year,cl
          mov month,dh
          mov day,dl
       } 
    
       switch(month)
       {
           case 16: month = 10; 
                     break; /* 10000 BCD October  */	
           case 17: month = 11;
                     break; /* 10001 BCD November */
           case 18: month = 12;
                     break; /* 10010 BCD December */
           default: break;
       };	
    
       printf("System Date: %s %x, %x%s%x",
               months[month], day, cent,
               (year > 9 ? "" : "0"), year); 
       return 0;
    }
    I *think* that it covers all cases, but you'd have to run through all the combinations to know for sure.
    Last edited by ronin; 02-06-2003 at 03:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 09:18 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Help w/project + linked list Plz Read
    By havoq93 in forum C++ Programming
    Replies: 13
    Last Post: 10-27-2002, 02:53 PM
  4. Help with ifstream read plz
    By dp_goose in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2002, 06:35 AM
  5. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM