h.txt
资源名称:C.rar [点击查看]
上传用户:harvey99
上传日期:2020-01-11
资源大小:938k
文件大小:6k
源码类别:

其他书籍

开发平台:

CHM

  1.  返回>>C语言函数大全
  2. 函数名: harderr
  3. 功  能: 建立一个硬件错误处理程序
  4. 用  法: void harderr(int (*fptr)());
  5. 程序例:
  6. /*This program will trap disk errors and prompt
  7. the user for action. Try running it with no
  8. disk in drive A: to invoke its functions.*/ 
  9. #include <stdio.h>
  10. #include <conio.h>
  11. #include <dos.h> 
  12. #define IGNORE  0
  13. #define RETRY   1
  14. #define ABORT   2
  15. int buf[500];
  16. /*define the error messages for trapping disk problems*/
  17. static char *err_msg[] = {
  18.     "write protect",
  19.     "unknown unit",
  20.     "drive not ready",
  21.     "unknown command",
  22.     "data error (CRC)",
  23.     "bad request",
  24.     "seek error",
  25.     "unknown media type",
  26.     "sector not found",
  27.     "printer out of paper",
  28.     "write fault",
  29.     "read fault",
  30.     "general failure",
  31.     "reserved",
  32.     "reserved",
  33.     "invalid disk change"
  34. };
  35. error_win(char *msg)
  36. {
  37.    int retval;
  38.    cputs(msg);
  39. /*prompt for user to press a key to abort, retry, ignore*/
  40.    while(1)
  41.    {
  42.        retval= getch();
  43.        if (retval == 'a' || retval == 'A')
  44.        {
  45.     retval = ABORT;
  46.     break;
  47.        }
  48.        if (retval == 'r' || retval == 'R')
  49.        {
  50.     retval = RETRY;
  51.     break;
  52.        }
  53.        if (retval == 'i' || retval == 'I')
  54.        {
  55.            retval = IGNORE;
  56.            break;
  57.        }
  58.    }
  59.    return(retval);
  60. }
  61. /*pragma warn -par reduces warnings which occur
  62. due to the non use of the parameters errval,
  63. bp and si to the handler.*/
  64. #pragma warn -par
  65. int handler(int errval,int ax,int bp,int si)
  66. {
  67.    static char msg[80];
  68.    unsigned di;
  69.    int drive;
  70.    int errorno;
  71.    di= _DI;
  72. /*if this is not a disk error then it was
  73. another device having trouble*/
  74.    if (ax < 0)
  75.    {
  76.       /* report the error */
  77.       error_win("Device error");
  78.       /* and return to the program directly requesting abort */
  79.       hardretn(ABORT);
  80.    }
  81. /* otherwise it was a disk error */
  82.    drive = ax & 0x00FF;
  83.    errorno = di & 0x00FF;
  84. /* report which error it was */
  85.    sprintf(msg, "Error: %s on drive %crnA)bort, R)etry, I)gnore: ",
  86.     err_msg[errorno], 'A' + drive);
  87. /*
  88. return to the program via dos interrupt 0x23 with abort, retry,
  89. or ignore as input by the user.
  90. */
  91.    hardresume(error_win(msg));
  92.    return ABORT;
  93. }
  94. #pragma warn +par
  95. int main(void)
  96. {
  97. /*
  98. install our handler on the hardware problem interrupt
  99. */
  100.    harderr(handler);
  101.    clrscr();
  102.    printf("Make sure there is no disk in drive A:n");
  103.    printf("Press any key ....n");
  104.    getch();
  105.    printf("Trying to access drive A:n");
  106.    printf("fopen returned %pn",fopen("A:temp.dat", "w"));
  107.    return 0;
  108. }
  109.  
  110.  
  111. 函数名: hardresume
  112. 功  能: 硬件错误处理函数
  113. 用  法: void hardresume(int rescode);
  114. 程序例:
  115.  
  116. /* This program will trap disk errors and prompt the user for action. */
  117. /* Try running it with no disk in drive A: to invoke its functions    */
  118. #include <stdio.h>
  119. #include <conio.h>
  120. #include <dos.h>
  121. #define IGNORE  0
  122. #define RETRY   1
  123. #define ABORT   2
  124. int buf[500];
  125. /* define the error messages for trapping disk problems */
  126. static char *err_msg[] = {
  127.     "write protect",
  128.     "unknown unit",
  129.     "drive not ready",
  130.     "unknown command",
  131.     "data error (CRC)",
  132.     "bad request",
  133.     "seek error",
  134.     "unknown media type",
  135.     "sector not found",
  136.     "printer out of paper",
  137.     "write fault",
  138.     "read fault",
  139.     "general failure",
  140.     "reserved",
  141.     "reserved",
  142.     "invalid disk change"
  143. };
  144. error_win(char *msg)
  145. {
  146.    int retval;
  147.    cputs(msg);
  148. /* prompt for user to press a key to abort, retry, ignore */
  149.    while(1)
  150.    {
  151.        retval= getch();
  152.        if (retval == 'a' || retval == 'A')
  153.        {
  154.            retval = ABORT;
  155.            break;
  156.        }
  157.        if (retval == 'r' || retval == 'R')
  158.        {
  159.            retval = RETRY;
  160.            break;
  161.        }
  162.        if (retval == 'i' || retval == 'I')
  163.        {
  164.            retval = IGNORE;
  165.            break;
  166.        }
  167.    }
  168.    return(retval);
  169. }
  170. /* pragma warn -par reduces warnings which occur due to the non use */
  171. /* of the parameters errval, bp and si to the handler.              */
  172. #pragma warn -par
  173. int handler(int errval,int ax,int bp,int si)
  174. {
  175.    static char msg[80];
  176.    unsigned di;
  177.    int drive;
  178.    int errorno;
  179.    di= _DI;
  180. /* if this is not a disk error then it was another device having trouble */
  181.    if (ax < 0)
  182.    {
  183.       /* report the error */
  184.       error_win("Device error");
  185.       /* and return to the program directly
  186.       requesting abort */
  187.       hardretn(ABORT);
  188.    }
  189. /* otherwise it was a disk error */
  190.    drive = ax & 0x00FF;
  191.    errorno = di & 0x00FF;
  192. /* report which error it was */
  193.    sprintf(msg, "Error: %s on drive %crnA)bort, R)etry, I)gnore: ",
  194.            err_msg[errorno], 'A' + drive);
  195. /* return to the program via dos interrupt 0x23 with abort, retry */
  196. /* or ignore as input by the user.  */
  197.    hardresume(error_win(msg));
  198.    return ABORT;
  199. }
  200. #pragma warn +par
  201. int main(void)
  202. {
  203. /* install our handler on the hardware problem interrupt */
  204.    harderr(handler);
  205.    clrscr();
  206.    printf("Make sure there is no disk in drive A:n");
  207.    printf("Press any key ....n");
  208.    getch();
  209.    printf("Trying to access drive A:n");
  210.    printf("fopen returned %pn",fopen("A:temp.dat", "w"));
  211.    return 0;
  212. }
  213.  
  214.  
  215. 函数名: highvideo
  216. 功  能: 选择高亮度文本字符
  217. 用  法: void highvideo(void);
  218. 程序例:
  219. #include <conio.h>
  220. int main(void)
  221. {
  222.    clrscr();
  223.    lowvideo();
  224.    cprintf("Low Intensity textrn");
  225.    highvideo();
  226.    gotoxy(1,2);
  227.    cprintf("High Intensity Textrn");
  228.    return 0;
  229. }
  230.  
  231.  
  232. 函数名: hypot
  233. 功  能: 计算直角三角形的斜边长
  234. 用  法: double hypot(double x, double y);
  235. 程序例:
  236. #include <stdio.h>
  237. #include <math.h>
  238. int main(void)
  239. {
  240.    double result;
  241.    double x = 3.0;
  242.    double y = 4.0;
  243.    result = hypot(x, y);
  244.    printf("The hypotenuse is: %lfn", result);
  245.    return 0;
  246. }
  247.