metamorphy
Programmer
Is there a better way to do what I'm trying to do here? This program will only compile as a DOS .exe on my old Microsoft c++ compiler (New c++ doesn't support far??). I'm trying to write a function in C that will "sleep" for a certain length of time without using very much sytem resources. Am I on the right track at all?? I've heard of sleep() in C++ but I was trying to use only C. Whats the best way??
#include <dos.h>
#include <bios.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define TIME_INTERRUPT 0x1C
void (_interrupt far *old_isr)();
long counter =0;
int seconds=0;
void _interrupt far timer(void){
counter++;
if(counter > 19){counter = 0; seconds++;}
old_isr();
}
void main(void){
old_isr = _dos_getvect(TIME_INTERRUPT);
_dos_setvect(TIME_INTERRUPT, timer);
while(!_kbhit()){
if(counter >=18){counter = 0; seconds++;
printf("time elapsed is %d seconds\n", seconds);
}
else{}
}
_dos_setvect(TIME_INTERRUPT,old_isr);
}
#include <dos.h>
#include <bios.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define TIME_INTERRUPT 0x1C
void (_interrupt far *old_isr)();
long counter =0;
int seconds=0;
void _interrupt far timer(void){
counter++;
if(counter > 19){counter = 0; seconds++;}
old_isr();
}
void main(void){
old_isr = _dos_getvect(TIME_INTERRUPT);
_dos_setvect(TIME_INTERRUPT, timer);
while(!_kbhit()){
if(counter >=18){counter = 0; seconds++;
printf("time elapsed is %d seconds\n", seconds);
}
else{}
}
_dos_setvect(TIME_INTERRUPT,old_isr);
}