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

其他书籍

开发平台:

CHM

  1.  返回>>C语言函数大全
  2. 函数名: labs
  3. 功  能: 取长整型绝对值
  4. 用  法: long labs(long n);
  5. 程序例: 
  6. #include <stdio.h> 
  7. #include <math.h>
  8. int main(void)
  9. {
  10.    long result;
  11.    long x = -12345678L;
  12.    result= labs(x);
  13.    printf("number: %ld abs value: %ldn",
  14.       x, result);
  15.    return 0;
  16. }
  17.  
  18.  
  19.  
  20. 函数名: ldexp
  21. 功  能: 计算value*2的幂
  22. 用  法: double ldexp(double value, int exp);
  23. 程序例:
  24. #include <stdio.h>
  25. #include <math.h>
  26. int main(void)
  27. {
  28.    double value;
  29.    double x = 2;
  30.    /* ldexp raises 2 by a power of 3
  31.       then multiplies the result by 2   */
  32.    value = ldexp(x,3);
  33.    printf("The ldexp value is: %lfn",
  34.       value);
  35.    return 0;
  36. }
  37.  
  38.  
  39. 函数名: ldiv
  40. 功  能: 两个长整型数相除, 返回商和余数
  41. 用  法: ldiv_t ldiv(long lnumer, long ldenom);
  42. 程序例:
  43. /* ldiv example */
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. int main(void)
  47. {
  48.    ldiv_t lx;
  49.    lx = ldiv(100000L, 30000L);
  50.    printf("100000 div 30000 = %ld remainder %ldn", lx.quot, lx.rem);
  51.    return 0;
  52. }
  53.  
  54.  
  55.  
  56. 函数名: lfind
  57. 功  能: 执行线性搜索
  58. 用  法: void *lfind(void *key, void *base, int *nelem, int width,
  59.       int (*fcmp)());
  60. 程序例:
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. int compare(int *x, int *y)
  64. {
  65.    return( *x - *y );
  66. }
  67. int main(void)
  68. {
  69.    int array[5] = {35, 87, 46, 99, 12};
  70.    size_t nelem = 5;
  71.    int key;
  72.    int *result;
  73.    key = 99;
  74.    result = lfind(&key, array, &nelem,
  75.         sizeof(int), (int(*)(const void *,const void *))compare);
  76.    if (result)
  77.       printf("Number %d foundn",key);
  78.    else
  79.       printf("Number %d not foundn",key);
  80.    return 0;
  81. }
  82.  
  83.  
  84. 函数名: line
  85. 功  能: 在指定两点间画一直线
  86. 用  法: void far line(int x0, int y0, int x1, int y1);
  87. 程序例:
  88. #include <graphics.h>
  89. #include <stdlib.h>
  90. #include <stdio.h>
  91. #include <conio.h>
  92. int main(void)
  93. {
  94.    /* request auto detection */
  95.    int gdriver = DETECT, gmode, errorcode;
  96.    int xmax, ymax;
  97.    /* initialize graphics and local variables */
  98.    initgraph(&gdriver, &gmode, "");
  99.    /* read result of initialization */
  100.    errorcode = graphresult();
  101.    /* an error occurred */
  102.    if (errorcode != grOk)
  103.    {
  104.       printf("Graphics error: %sn",
  105.              grapherrormsg(errorcode));
  106.       printf("Press any key to halt:");
  107.       getch();
  108.       exit(1);
  109.    }
  110.    setcolor(getmaxcolor());
  111.    xmax = getmaxx();
  112.    ymax = getmaxy();
  113.    /* draw a diagonal line */
  114.    line(0, 0, xmax, ymax);
  115.    /* clean up */
  116.    getch();
  117.    closegraph();
  118.    return 0;
  119. }
  120.  
  121.  
  122. 函数名: linerel
  123. 功  能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线
  124. 用  法: void far linerel(int dx, int dy);
  125. 程序例:
  126. #include <graphics.h>
  127. #include <stdlib.h>
  128. #include <stdio.h>
  129. #include <conio.h>
  130. int main(void)
  131. {
  132.    /* request auto detection */
  133.    int gdriver = DETECT, gmode, errorcode;
  134.    char msg[80];
  135.    /* initialize graphics and local variables */
  136.    initgraph(&gdriver, &gmode, "");
  137.    /* read result of initialization */
  138.    errorcode = graphresult();
  139.    if (errorcode != grOk)
  140.    {
  141.       printf("Graphics error: %sn",
  142.   grapherrormsg(errorcode));
  143.       printf("Press any key to halt:");
  144.       getch();
  145.       exit(1);
  146.    }
  147.    /* move the C.P. to location (20, 30) */
  148.    moveto(20, 30);
  149.    /* create and output a
  150.       message at (20, 30) */
  151.    sprintf(msg, " (%d, %d)", getx(), gety());
  152.    outtextxy(20, 30, msg);
  153.    /* draw a line to a point a relative
  154.       distance away from the current
  155.       value of C.P.   */
  156.    linerel(100, 100);
  157.    /* create and output a message at C.P. */
  158.    sprintf(msg, " (%d, %d)", getx(), gety());
  159.    outtext(msg);
  160.    /* clean up */
  161.    getch();
  162.    closegraph();
  163.    return 0;
  164. }
  165.  
  166. 函数名: localtime
  167. 功  能: 把日期和时间转变为结构
  168. 用  法: struct tm *localtime(long *clock);
  169. 程序例:
  170. #include <time.h>
  171. #include <stdio.h>
  172. #include <dos.h>
  173. int main(void)
  174. {
  175.    time_t timer;
  176.    struct tm *tblock;
  177.    /* gets time of day */
  178.    timer = time(NULL);
  179.    /* converts date/time to a structure */
  180.    tblock = localtime(&timer);
  181.    printf("Local time is: %s", asctime(tblock));
  182.    return 0;
  183. }
  184.  
  185.  
  186.  
  187. 函数名: lock
  188. 功  能: 设置文件共享锁
  189. 用  法: int lock(int handle, long offset, long length);
  190. 程序例:
  191. #include <io.h>
  192. #include <fcntl.h>
  193. #include <sysstat.h>
  194. #include <process.h>
  195. #include <share.h>
  196. #include <stdio.h>
  197. int main(void)
  198. {
  199.    int handle, status;
  200.    long length;
  201.    /* Must have DOS Share.exe loaded for */
  202.    /* file locking to function properly */
  203.    handle = sopen("c:\autoexec.bat",
  204.       O_RDONLY,SH_DENYNO,S_IREAD);
  205.    if (handle < 0)
  206.    {
  207.       printf("sopen failedn");
  208.       exit(1);
  209.    }
  210.    length = filelength(handle);
  211.    status = lock(handle,0L,length/2);
  212.    if (status == 0)
  213.       printf("lock succeededn");
  214.    else
  215.       printf("lock failedn");
  216.    status = unlock(handle,0L,length/2);
  217.    if (status == 0)
  218.       printf("unlock succeededn");
  219.    else
  220.       printf("unlock failedn");
  221.    close(handle);
  222.    return 0;
  223. }
  224.  
  225.  
  226. 函数名: log
  227. 功  能: 对数函数ln(x)
  228. 用  法: double log(double x);
  229. 程序例:
  230. #include <math.h>
  231. #include <stdio.h>
  232. int main(void)
  233. {
  234.    double result;
  235.    double x = 8.6872;
  236.    result = log(x);
  237.    printf("The natural log of %lf is %lfn", x, result);
  238.    return 0;
  239. }
  240.  
  241.  
  242. 函数名: log10
  243. 功  能: 对数函数log
  244. 用  法: double log10(double x);
  245. 程序例:
  246. #include <math.h>
  247. #include <stdio.h>
  248. int main(void)
  249. {
  250.    double result;
  251.    double x = 800.6872;
  252.    result = log10(x);
  253.    printf("The common log of %lf is %lfn", x, result);
  254.    return 0;
  255. }
  256.  
  257.  
  258.  
  259. 函数名: longjump
  260. 功  能: 执行非局部转移
  261. 用  法: void longjump(jmp_buf env, int val);
  262. 程序例:
  263. #include <stdio.h>
  264. #include <setjmp.h>
  265. #include <stdlib.h>
  266. void subroutine(jmp_buf);
  267. int main(void)
  268. {
  269.    int value;
  270.    jmp_buf jumper;
  271.    value = setjmp(jumper);
  272.    if (value != 0)
  273.    {
  274.       printf("Longjmp with value %dn", value);
  275.       exit(value);
  276.    }
  277.    printf("About to call subroutine ... n");
  278.    subroutine(jumper);
  279.    return 0;
  280. }
  281. void subroutine(jmp_buf jumper)
  282. {
  283.    longjmp(jumper,1);
  284. }
  285.  
  286.  
  287.  
  288. 函数名: lowvideo
  289. 功  能: 选择低亮度字符
  290. 用  法: void lowvideo(void);
  291. 程序例:
  292. #include <conio.h>
  293. int main(void)
  294. {
  295.    clrscr();
  296.    highvideo();
  297.    cprintf("High Intesity Textrn");
  298.    lowvideo();
  299.    gotoxy(1,2);
  300.    cprintf("Low Intensity Textrn");
  301.    return 0;
  302. }
  303.  
  304.  
  305.  
  306. 函数名: lrotl, _lrotl
  307. 功  能: 将无符号长整型数向左循环移位
  308. 用  法: unsigned long lrotl(unsigned long lvalue, int count);
  309.  unsigned long _lrotl(unsigned long lvalue, int count);
  310. 程序例:
  311. /* lrotl example */
  312. #include <stdlib.h>
  313. #include <stdio.h>
  314. int main(void)
  315. {
  316.    unsigned long result;
  317.    unsigned long value = 100;
  318.    result = _lrotl(value,1);
  319.    printf("The value %lu rotated left one bit is: %lun", value, result);
  320.    return 0;
  321. }
  322.  
  323.  
  324. 函数名: lsearch
  325. 功  能: 线性搜索
  326. 用  法: void *lsearch(const void *key, void *base, size_t *nelem,
  327.        size_t width, int (*fcmp)(const void *, const void *));
  328. 程序例:
  329. #include <stdio.h>
  330. #include <stdlib.h>
  331. int compare(int *x, int *y)
  332. {
  333.    return( *x - *y );
  334. }
  335. int main(void)
  336. {
  337.    int array[5] = {35, 87, 46, 99, 12};
  338.    size_t nelem = 5;
  339.    int key;
  340.    int *result;
  341.    key = 99;
  342.    result = lfind(&key, array, &nelem,
  343.                sizeof(int), (int(*)(const void *,const void *))compare);
  344.    if (result)
  345.       printf("Number %d foundn",key);
  346.    else
  347.       printf("Number %d not foundn",key);
  348.    return 0;
  349. }
  350.  
  351.  
  352.  
  353. 函数名: lseek
  354. 功  能: 移动文件读/写指针
  355. 用  法: long lseek(int handle, long offset, int fromwhere);
  356. 程序例:
  357. #include <sysstat.h>
  358. #include <string.h>
  359. #include <stdio.h>
  360. #include <fcntl.h>
  361. #include <io.h>
  362. int main(void)
  363. {
  364.    int handle;
  365.    char msg[] = "This is a test";
  366.    char ch;
  367.    /* create a file */
  368.    handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
  369.    /* write some data to the file */
  370.    write(handle, msg, strlen(msg));
  371.    /* seek to the begining of the file */
  372.    lseek(handle, 0L, SEEK_SET);
  373.    /* reads chars from the file until we hit EOF */
  374.    do
  375.    {
  376.       read(handle, &ch, 1);
  377.       printf("%c", ch);
  378.    }  while (!eof(handle));
  379.    close(handle);
  380.    return 0;
  381. }
  382.