C语言函数大全(h开头)

函数名: harderr

功能: 建立一个硬件错误处理程序

用法: void harderr(int (*fptr)());

程序例:

/*This program will trap disk errors and prompt
the user for action. Try running it with no
disk in drive A: to invoke its functions.*/
#include
#include
#include
#define IGNORE 0
#define RETRY 1
#define ABORT 2
int buf[500];
/*define the error messages for trapping disk problems*/
static char *err_msg[] = {
"write protect",
"unknown unit",
"drive not ready",
"unknown command",
"data error (CRC)",
"bad request",
"seek error",
"unknown media type",
"sector not found",
"printer out of paper",
"write fault",
"read fault",
"general failure",
"reserved",
"reserved",
"invalid disk change"
};
error_win(char *msg)
{
int retval;
cputs(msg);
/*prompt for user to press a key to abort, retry, ignore*/
while(1)
{
retval= getch();
if (retval == 'a' || retval == 'A')
{
retval = ABORT;
break;
}
if (retval == 'r' || retval == 'R')
{
retval = RETRY;
break;
}
if (retval == 'i' || retval == 'I')
{
retval = IGNORE;
break;
}
}
return(retval);
}
/*pragma warn -par reduces warnings which occur
due to the non use of the parameters errval,
bp and si to the handler.*/
#pragma warn -par
int handler(int errval,int ax,int bp,int si)
{
static char msg[80];
unsigned di;
int drive;
int errorno;
di= _DI;
/*if this is not a disk error then it was
another device having trouble*/
if (ax < 0)
{
/* report the error */
error_win("Device error");
/* and return to the program directly requesting abort */
hardretn(ABORT);
}
/* otherwise it was a disk error */
drive = ax & 0x00FF;
errorno = di & 0x00FF;
/* report which error it was */
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
err_msg[errorno], 'A' + drive);
/*
return to the program via dos interrupt 0x23 with abort, retry,
or ignore as input by the user.
*/
hardresume(error_win(msg));
return ABORT;
}
#pragma warn +par
int main(void)
{
/*
install our handler on the hardware problem interrupt
*/
harderr(handler);
clrscr();
printf("Make sure there is no disk in drive A:\n");
printf("Press any key ....\n");
getch();
printf("Trying to access drive A:\n");
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
return 0;
}

时间: 2024-10-01 09:06:21

C语言函数大全(h开头)的相关文章

C语言函数大全(a开头)

函数名: abort 功能: 异常终止一个进程 用法: void abort(void); 程序例: #include #include int main(void) { printf("Calling abort()\n"); abort(); return 0; /* This is never reached */ } 函数名: abs 功能: 求整数的绝对值 用法: int abs(int i); 程序例: #include #include int main(void) {

C语言函数大全(b开头)

函数名: bar 功能: 画一个二维条形图 用法: void far bar(int left, int top, int right, int bottom); 程序例: #include #include #include #include int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int midx, midy, i; /* initialize graphics

C语言函数大全(c开头)

函数名: cabs 功能: 计算复数的绝对值 用法: double cabs(struct complex z); 程序例: #include #include int main(void) { struct complex z; double val; z.x = 2.0; z.y = 1.0; val = cabs(z); printf("The absolute value of %.2lfi %.2lfj is %.2lf", z.x, z.y, val); return 0;

C语言函数大全(d开头)

函数名: delay 功能: 将程序的执行暂停一段时间(毫秒) 用法: void delay(unsigned milliseconds); 程序例: /* Emits a 440-Hz tone for 500 milliseconds */ #include int main(void) { sound(440); delay(500); nosound(); return 0; } 函数名: delline 功能: 在文本窗口中删去一行 用法: void delline(void); 程序

C语言函数大全(e开头)

函数名: ecvt 功能: 把一个浮点数转换为字符串 用法: char ecvt(double value, int ndigit, int *decpt, int *sign); 程序例: #include #include #include int main(void) { char *string; double value; int dec, sign; int ndig = 10; clrscr(); value = 9.876; string = ecvt(value, ndig,

C语言函数大全(g开头)

函数名: gcvt 功能: 把浮点数转换成字符串 用法: char *gcvt(double value, int ndigit, char *buf); 程序例: #include #include int main(void) { char str[25]; double num; int sig = 5; /* significant digits */ /* a regular number */ num = 9.876; gcvt(num, sig, str); printf("str

C语言函数大全(i开头)

函数名: imagesize 功能: 返回保存位图像所需的字节数 用法: unsigned far imagesize(int left, int top, int right, int bottom); 程序例: #include #include #include #include #define ARROW_SIZE 10 void draw_arrow(int x, int y); int main(void) { /* request autodetection */ int gdri

C语言函数大全(k开头)

函数名: kbhit 功能: 检查当前按下的键 用法: int kbhit(void); 程序例: #include int main(void) { cprintf("Press any key to continue:"); while (!kbhit()) /* do nothing */ ; cprintf("\r\nA key was pressed...\r\n"); return 0; } 函数名: keep 功能: 退出并继续驻留 用法: void

C语言函数大全(l开头)

函数名: labs 用法: long labs(long n); 程序例: #include #include int main(void) { long result; long x = -12345678L; result= labs(x); printf("number: %ld abs value: %ld\n", x, result); return 0; } 函数名: ldexp 功能: 计算value*2的幂 用法: double ldexp(double value,