a.txt
Upload User: harvey99
Upload Date: 2020-01-11
Package Size: 938k
Code Size: 7k
Category:

Other Books

Development Platform:

CHM

  1. 函数名: abort
  2. 功  能: 异常终止一个进程
  3. 用  法: void abort(void);
  4. 程序例:
  5. #include <stdio.h>
  6. #include <stdlib.h> 
  7. int main(void)
  8. {
  9.   printf("Calling abort()n");
  10.   abort();
  11.   return 0; /* This is never reached */
  12. }
  13.  
  14.  
  15. 函数名: abs
  16. 功  能: 求整数的绝对值
  17. 用  法: int abs(int i);
  18. 程序例:
  19. #include <stdio.h>
  20. #include <math.h>
  21. int main(void)
  22. {
  23.   int number = -1234;
  24.   printf("number: %d  absolute value: %dn", number, abs(number));
  25.   return 0;
  26. }
  27.  
  28.  
  29. 函数名: absread, abswirte
  30. 功  能: 绝对磁盘扇区读、写数据
  31. 用  法: int absread(int drive, int nsects, int sectno, void *buffer);
  32.  int abswrite(int drive, int nsects, in tsectno, void *buffer);
  33. 程序例:
  34. /* absread example */
  35. #include <stdio.h>
  36. #include <conio.h>
  37. #include <process.h>
  38. #include <dos.h>
  39. int main(void)
  40. {
  41.   int i, strt, ch_out, sector;
  42.   char buf[512];
  43.   printf("Insert a diskette into drive A and press any keyn");
  44.   getch();
  45.   sector = 0;
  46.   if (absread(0, 1, sector, &buf) != 0)
  47.   {
  48.      perror("Disk problem");
  49.      exit(1);
  50.   }
  51.   printf("Read OKn");
  52.   strt = 3;
  53.   for (i=0; i<80; i++)
  54.   {
  55.      ch_out = buf[strt+i];
  56.      putchar(ch_out);
  57.   }
  58.   printf("n");
  59.   return(0);
  60. }
  61.  
  62.  
  63.  
  64. 函数名: access
  65. 功  能: 确定文件的访问权限
  66. 用  法: int access(const char *filename, int amode);
  67. 程序例:
  68. #include <stdio.h>
  69. #include <io.h>
  70. int file_exists(char *filename);
  71. int main(void)
  72. {
  73.   printf("Does NOTEXIST.FIL exist: %sn",
  74.   file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
  75.   return 0;
  76. }
  77. int file_exists(char *filename)
  78. {
  79.   return (access(filename, 0) == 0);
  80. }
  81.  
  82. 函数名: acos
  83. 功  能: 反余弦函数
  84. 用  法: double acos(double x);
  85. 程序例:
  86. #include <stdio.h>
  87. #include <math.h>
  88. int main(void)
  89. {
  90.   double result;
  91.   double x = 0.5;
  92.   result = acos(x);
  93.   printf("The arc cosine of %lf is %lfn", x, result);
  94.   return 0;
  95. }
  96.  
  97.  
  98. 函数名: allocmem
  99. 功  能: 分配DOS存储段
  100. 用  法: int allocmem(unsigned size, unsigned *seg);
  101. 程序例:
  102. #include <dos.h>
  103. #include <alloc.h>
  104. #include <stdio.h>
  105. int main(void)
  106. {
  107.   unsigned int size, segp;
  108.   int stat;
  109.   size = 64; /* (64 x 16) = 1024 bytes */
  110.   stat = allocmem(size, &segp);
  111.   if (stat == -1)
  112.      printf("Allocated memory at segment: %xn", segp);
  113.   else
  114.      printf("Failed: maximum number of paragraphs available is %un",
  115.             stat);
  116.   return 0;
  117. }
  118.  
  119.  
  120. 函数名: arc
  121. 功  能: 画一弧线
  122. 用  法: void far arc(int x, int y, int stangle, int endangle, int radius);
  123. 程序例:
  124. #include <graphics.h>
  125. #include <stdlib.h>
  126. #include <stdio.h>
  127. #include <conio.h>
  128. int main(void)
  129. {
  130.     /* request auto detection */
  131.    int gdriver = DETECT, gmode, errorcode;
  132.    int midx, midy;
  133.    int stangle = 45, endangle = 135;
  134.    int radius = 100;
  135.    /* initialize graphics and local variables */
  136.    initgraph(&gdriver, &gmode, "");
  137.    /* read result of initialization */
  138.    errorcode = graphresult();    /* an error occurred */
  139.    if (errorcode != grOk)
  140.    {
  141.       printf("Graphics error: %sn", grapherrormsg(errorcode));
  142.       printf("Press any key to halt:");
  143.       getch();
  144.       exit(1);    /* terminate with an error code */
  145.    }
  146.    midx = getmaxx() / 2;
  147.    midy = getmaxy() / 2;
  148.    setcolor(getmaxcolor());
  149.    /* draw arc */
  150.    arc(midx, midy, stangle, endangle, radius);
  151.    /* clean up */
  152.    getch();
  153.    closegraph();
  154.    return 0;
  155. }
  156.  
  157.  
  158. 函数名: asctime
  159. 功  能: 转换日期和时间为ASCII码
  160. 用  法: char *asctime(const struct tm *tblock);
  161. 程序例:
  162. #include <stdio.h>
  163. #include <string.h>
  164. #include <time.h>
  165. int main(void)
  166. {
  167.    struct tm t;
  168.    char str[80];
  169.    /* sample loading of tm structure  */
  170.    t.tm_sec    = 1;  /* Seconds */
  171.    t.tm_min    = 30; /* Minutes */
  172.    t.tm_hour   = 9;  /* Hour */
  173.    t.tm_mday   = 22; /* Day of the Month  */
  174.    t.tm_mon    = 11; /* Month */
  175.    t.tm_year   = 56; /* Year - does not include century */
  176.    t.tm_wday   = 4;  /* Day of the week  */
  177.    t.tm_yday   = 0;  /* Does not show in asctime  */
  178.    t.tm_isdst  = 0;  /* Is Daylight SavTime; does not show in asctime */
  179.    /* converts structure to null terminated
  180.    string */
  181.    strcpy(str, asctime(&t));
  182.    printf("%sn", str);
  183.    return 0;
  184. }
  185.  
  186.  
  187.  
  188. 函数名: asin
  189. 功  能: 反正弦函数
  190. 用  法: double asin(double x);
  191. 程序例:
  192. #include <stdio.h>
  193. #include <math.h>
  194. int main(void)
  195. {
  196.    double result;
  197.    double x = 0.5;
  198.    result = asin(x);
  199.    printf("The arc sin of %lf is %lfn", x, result);
  200.    return(0);
  201. }
  202.  
  203.  
  204.  
  205. 函数名: assert
  206. 功  能: 测试一个条件并可能使程序终止
  207. 用  法: void assert(int test);
  208. 程序例:
  209. #include <assert.h>
  210. #include <stdio.h>
  211. #include <stdlib.h>
  212. struct ITEM {
  213.    int key;
  214.    int value;
  215. };
  216. /* add item to list, make sure list is not null */
  217. void additem(struct ITEM *itemptr) {
  218.    assert(itemptr != NULL);
  219.    /* add item to list */
  220. }
  221. int main(void)
  222. {
  223.    additem(NULL);
  224.    return 0;
  225. }
  226.  
  227.  
  228.  
  229. 函数名: atan
  230. 功  能: 反正切函数
  231. 用  法: double atan(double x);
  232. 程序例:
  233. #include <stdio.h>
  234. #include <math.h>
  235. int main(void)
  236. {
  237.    double result;
  238.    double x = 0.5;
  239.    result = atan(x);
  240.    printf("The arc tangent of %lf is %lfn", x, result);
  241.    return(0);
  242. }
  243.  
  244.  
  245. 函数名: atan2
  246. 功  能: 计算Y/X的反正切值
  247. 用  法: double atan2(double y, double x);
  248. 程序例:
  249. #include <stdio.h>
  250. #include <math.h>
  251. int main(void)
  252. {
  253.    double result;
  254.    double x = 90.0, y = 45.0;
  255.    result = atan2(y, x);
  256.    printf("The arc tangent ratio of %lf is %lfn", (y / x), result);
  257.    return 0;
  258. }
  259.  
  260.  
  261. 函数名: atexit
  262. 功  能: 注册终止函数
  263. 用  法: int atexit(atexit_t func);
  264. 程序例:
  265. #include <stdio.h>
  266. #include <stdlib.h>
  267. void exit_fn1(void)
  268. {
  269.    printf("Exit function #1 calledn");
  270. }
  271. void exit_fn2(void)
  272. {
  273.    printf("Exit function #2 calledn");
  274. }
  275. int main(void)
  276. {
  277.    /* post exit function #1 */
  278.    atexit(exit_fn1);
  279.    /* post exit function #2 */
  280.    atexit(exit_fn2);
  281.    return 0;
  282. }
  283.  
  284.  
  285.  
  286. 函数名: atof
  287. 功  能: 把字符串转换成浮点数
  288. 用  法: double atof(const char *nptr);
  289. 程序例:
  290. #include <stdlib.h>
  291. #include <stdio.h>
  292. int main(void)
  293. {
  294.    float f;
  295.    char *str = "12345.67";
  296.    f = atof(str);
  297.    printf("string = %s float = %fn", str, f);
  298.    return 0;
  299. }
  300.  
  301.  
  302. 函数名: atoi
  303. 功  能: 把字符串转换成长整型数
  304. 用  法: int atoi(const char *nptr);
  305. 程序例:
  306. #include <stdlib.h>
  307. #include <stdio.h>
  308. int main(void)
  309. {
  310.    int n;
  311.    char *str = "12345.67";
  312.    n = atoi(str);
  313.    printf("string = %s integer = %dn", str, n);
  314.    return 0;
  315. }
  316.  
  317.  
  318. 函数名: atol
  319. 功  能: 把字符串转换成长整型数
  320. 用  法: long atol(const char *nptr);
  321. 程序例:
  322. #include <stdlib.h>
  323. #include <stdio.h>
  324. int main(void)
  325. {
  326.    long l;
  327.    char *str = "98765432";
  328.    l = atol(lstr);
  329.    printf("string = %s integer = %ldn", str, l);
  330.    return(0);
  331. }