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

Other Books

Development Platform:

CHM

  1. 函数名: tan
  2. 功  能: 正切函数
  3. 用  法: double tan(double x);
  4. 程序例: 
  5. #include <stdio.h> 
  6. #include <math.h>
  7. int main(void)
  8. {
  9.    double result, x;
  10.    x = 0.5;
  11.    result = tan(x);
  12.    printf("The tan of %lf is %lfn", x, result);
  13.    return 0;
  14. }
  15.  
  16.  
  17.  
  18. 函数名: tanh
  19. 功  能: 双曲正切函数
  20. 用  法: double tanh(double x);
  21. 程序例:
  22. #include <stdio.h>
  23. #include <math.h>
  24. int main(void)
  25. {
  26.    double result, x;
  27.    x = 0.5;
  28.    result = tanh(x);
  29.    printf("The hyperbolic tangent of %lf is %lfn", x, result);
  30.    return 0;
  31. }
  32.  
  33.  
  34.  
  35.  
  36. 函数名: tell
  37. 功  能: 取文件指针的当前位置
  38. 用  法: long tell(int handle);
  39. 程序例:
  40. #include <string.h>
  41. #include <stdio.h>
  42. #include <fcntl.h>
  43. #include <io.h>
  44. int main(void)
  45. {
  46.    int handle;
  47.    char msg[] = "Hello world";
  48.    if ((handle = open("TEST.$$$", O_CREAT | O_TEXT | O_APPEND)) == -1)
  49.    {
  50.       perror("Error:");
  51.       return 1;
  52.    }
  53.    write(handle, msg, strlen(msg));
  54.    printf("The file pointer is at byte %ldn", tell(handle));
  55.    close(handle);
  56.    return 0;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. 函数名: textattr
  63. 功  能: 设置文本属性
  64. 用  法: void textattr(int attribute);
  65. 程序例:
  66. #include <conio.h>
  67. int main(void)
  68. {
  69.    int i;
  70.    clrscr();
  71.    for (i=0; i<9; i++)
  72.    {
  73.        textattr(i + ((i+1) << 4));
  74.        cprintf("This is a testrn");
  75.    }
  76.    return 0;
  77. }
  78.  
  79.  
  80.  
  81. 函数名: textbackground
  82. 功  能: 选择新的文本背景颜色
  83. 用  法: void textbackground(int color);
  84. 程序例:
  85. #include <conio.h>
  86. int main(void)
  87. {
  88.    int i, j;
  89.    clrscr();
  90.    for (i=0; i<9; i++)
  91.    {
  92.        for (j=0; j<80; j++)
  93.          cprintf("C");
  94.        cprintf("rn");
  95.        textcolor(i+1);
  96.        textbackground(i);
  97.    }
  98.    return 0;
  99. }
  100.  
  101.  
  102.  
  103. 函数名: textcolor
  104. 功  能: 在文本模式中选择新的字符颜色
  105. 用  法: void textcolor(int color);
  106. 程序例:
  107. #include <conio.h>
  108. int main(void)
  109. {
  110.    int i;
  111.    for (i=0; i<15; i++)
  112.    {
  113.        textcolor(i);
  114.        cprintf("Foreground Colorrn");
  115.    }
  116.    return 0;
  117. }
  118.  
  119.  
  120.  
  121. 函数名: textheight
  122. 功  能: 返回以像素为单位的字符串高度
  123. 用  法: int far textheight(char far *textstring);
  124. 程序例:
  125. #include <graphics.h>
  126. #include <stdlib.h>
  127. #include <stdio.h>
  128. #include <conio.h>
  129. int main(void)
  130. {
  131.    /* request auto detection */
  132.    int gdriver = DETECT, gmode, errorcode;
  133.    int y = 0;
  134.    int i;
  135.    char msg[80];
  136.    /* initialize graphics and local variables */
  137.    initgraph(&gdriver, &gmode, "");
  138.    /* read result of initialization */
  139.    errorcode = graphresult();
  140.    if (errorcode != grOk)  /* an error occurred */
  141.    {
  142.       printf("Graphics error: %sn", grapherrormsg(errorcode));
  143.       printf("Press any key to halt:");
  144.       getch();
  145.       exit(1); /* terminate with an error code */
  146.    }
  147.    /* draw some text on the screen */
  148.    for (i=1; i<11; i++)
  149.    {
  150.       /* select the text style, direction, and size */
  151.       settextstyle(TRIPLEX_FONT, HORIZ_DIR, i);
  152.       /* create a message string */
  153.       sprintf(msg, "Size: %d", i);
  154.       /* output the message */
  155.       outtextxy(1, y, msg);
  156.       /* advance to the next text line */
  157.       y += textheight(msg);
  158.    }
  159.    /* clean up */
  160.    getch();
  161.    closegraph();
  162.    return 0;
  163. }
  164.  
  165.  
  166.  
  167. 函数名: textmode
  168. 功  能: 将屏幕设置成文本模式
  169. 用  法: void textmode(int mode);
  170. 程序例:
  171. #include <conio.h>
  172. int main(void)
  173. {
  174.    textmode(BW40);
  175.    cprintf("ABC");
  176.    getch();
  177.    textmode(C40);
  178.    cprintf("ABC");
  179.    getch();
  180.    textmode(BW80);
  181.    cprintf("ABC");
  182.    getch();
  183.    textmode(C80);
  184.    cprintf("ABC");
  185.    getch();
  186.    textmode(MONO);
  187.    cprintf("ABC");
  188.    getch();
  189.    return 0;
  190. }
  191.  
  192.  
  193. 函数名: textwidth
  194. 功  能: 返回以像素为单位的字符串宽度
  195. 用  法: int far textwidth(char far *textstring);
  196. 程序例:
  197. #include <graphics.h>
  198. #include <stdlib.h>
  199. #include <stdio.h>
  200. #include <conio.h>
  201. int main(void)
  202. {
  203.    /* request auto detection */
  204.    int gdriver = DETECT, gmode, errorcode;
  205.    int x = 0, y = 0;
  206.    int i;
  207.    char msg[80];
  208.    /* initialize graphics and local variables */
  209.    initgraph(&gdriver, &gmode, "");
  210.    /* read result of initialization */
  211.    errorcode = graphresult();
  212.    if (errorcode != grOk)  /* an error occurred */
  213.    {
  214.       printf("Graphics error: %sn", grapherrormsg(errorcode));
  215.       printf("Press any key to halt:");
  216.       getch();
  217.       exit(1); /* terminate with an error code */
  218.    }
  219.    y = getmaxy() / 2;
  220.    settextjustify(LEFT_TEXT, CENTER_TEXT);
  221.    for (i=1; i<11; i++)
  222.    {
  223.       /* select the text style, direction, and size */
  224.       settextstyle(TRIPLEX_FONT, HORIZ_DIR, i);
  225.       /* create a message string */
  226.       sprintf(msg, "Size: %d", i);
  227.       /* output the message */
  228.       outtextxy(x, y, msg);
  229.       /* advance to the end of the text */
  230.       x += textwidth(msg);
  231.    }
  232.    /* clean up */
  233.    getch();
  234.    closegraph();
  235.    return 0;
  236. }
  237.  
  238.  
  239. 函数名: time
  240. 功  能: 取一天的时间
  241. 用  法: logn time(long *tloc);
  242. 程序例:
  243. #include <time.h>
  244. #include <stdio.h>
  245. #include <dos.h>
  246. int main(void)
  247. {
  248.    time_t t;
  249.    t = time(NULL);
  250.    printf("The number of seconds since January 1, 1970 is %ld",t);
  251.    return 0;
  252. }
  253.  
  254.  
  255.  
  256. 函数名: tmpfile
  257. 功  能: 以二进制方式打开暂存文件
  258. 用  法: FILE *tmpfile(void);
  259. 程序例:
  260. #include <stdio.h>
  261. #include <process.h>
  262. int main(void)
  263. {
  264.    FILE *tempfp;
  265.    tempfp = tmpfile();
  266.    if (tempfp)
  267.       printf("Temporary file createdn");
  268.    else
  269.    {
  270.       printf("Unable to create temporary filen");
  271.       exit(1);
  272.    }
  273.    return 0;
  274. }
  275.  
  276.  
  277.  
  278. 函数名: tmpnam
  279. 功  能: 创建一个唯一的文件名
  280. 用  法: char *tmpnam(char *sptr);
  281. 程序例:
  282. #include <stdio.h>
  283. int main(void)
  284. {
  285.    char name[13];
  286.    tmpnam(name);
  287.    printf("Temporary name: %sn", name);
  288.    return 0;
  289. }
  290.  
  291.  
  292.  
  293. 函数名: tolower
  294. 功  能: 把字符转换成小写字母
  295. 用  法: int tolower(int c);
  296. 程序例:
  297. #include <string.h>
  298. #include <stdio.h>
  299. #include <ctype.h>
  300. int main(void)
  301. {
  302.    int length, i;
  303.    char *string = "THIS IS A STRING";
  304.    length = strlen(string);
  305.    for (i=0; i<length; i++)
  306.    {
  307.        string[i] = tolower(string[i]);
  308.    }
  309.    printf("%sn",string);
  310.    return 0;
  311. }
  312.  
  313.  
  314. 函数名: toupper
  315. 功  能: 把字符转换成大写字母
  316. 用  法: int toupper(int c);
  317. 程序例:
  318. #include <string.h>
  319. #include <stdio.h>
  320. #include <ctype.h>
  321. int main(void)
  322. {
  323.    int length, i;
  324.    char *string = "this is a string";
  325.    length = strlen(string);
  326.    for (i=0; i<length; i++)
  327.    {
  328.       string[i] = toupper(string[i]);
  329.    }
  330.    printf("%sn",string);
  331.    return 0;
  332. }
  333.  
  334.  
  335. 函数名: tzset
  336. 功  能: UNIX时间兼容函数
  337. 用  法: void tzset(void);
  338. 程序例:
  339. #include <time.h>
  340. #include <stdlib.h>
  341. #include <stdio.h>
  342. int main(void)
  343. {
  344.    time_t td;
  345.    putenv("TZ=PST8PDT");
  346.    tzset();
  347.    time(&td);
  348.    printf("Current time = %sn", asctime(localtime(&td)));
  349.    return 0;
  350. }