📄 037.htm
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->T</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 T">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - T">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD CLASS="tt3" VALIGN="top" width="8%" bgcolor="#e0e0e0"><strong><A HREF="038.htm">后一页</A><BR>
<A HREF="036.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">T</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<P>函数名: tan
<BR>功 能: 正切函数
<BR>用 法: double tan(double x);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <math.h>
<BR>
<P>int main(void)
<BR>{
<BR> double result, x;
<BR>
<P> x = 0.5;
<BR> result = tan(x);
<BR> printf("The tan of %lf is %lf\n", x, result);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: tanh
<BR>功 能: 双曲正切函数
<BR>用 法: double tanh(double x);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <math.h>
<BR>
<P>int main(void)
<BR>{
<BR> double result, x;
<BR>
<P> x = 0.5;
<BR> result = tanh(x);
<BR> printf("The hyperbolic tangent of %lf is %lf\n", x, result);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<BR>
<P>函数名: tell
<BR>功 能: 取文件指针的当前位置
<BR>用 法: long tell(int handle);
<BR>程序例:
<BR>
<P>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <fcntl.h>
<BR>#include <io.h>
<BR>
<P>int main(void)
<BR>{
<BR> int handle;
<BR> char msg[] = "Hello world";
<BR>
<P> if ((handle = open("TEST.$$$", O_CREAT | O_TEXT | O_APPEND))
== -1)
<BR> {
<BR> perror("Error:");
<BR> return 1;
<BR> }
<BR> write(handle, msg, strlen(msg));
<BR> printf("The file pointer is at byte %ld\n", tell(handle));
<BR> close(handle);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<BR>
<P>函数名: textattr
<BR>功 能: 设置文本属性
<BR>用 法: void textattr(int attribute);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> int i;
<BR>
<P> clrscr();
<BR> for (i=0; i<9; i++)
<BR> {
<BR> textattr(i + ((i+1) << 4));
<BR> cprintf("This is a test\r\n");
<BR> }
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: textbackground
<BR>功 能: 选择新的文本背景颜色
<BR>用 法: void textbackground(int color);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> int i, j;
<BR>
<P> clrscr();
<BR> for (i=0; i<9; i++)
<BR> {
<BR> for (j=0; j<80; j++)
<BR> cprintf("C");
<BR> cprintf("\r\n");
<BR> textcolor(i+1);
<BR> textbackground(i);
<BR> }
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: textcolor
<BR>功 能: 在文本模式中选择新的字符颜色
<BR>用 法: void textcolor(int color);
<BR>程序例:
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> int i;
<BR>
<P> for (i=0; i<15; i++)
<BR> {
<BR> textcolor(i);
<BR> cprintf("Foreground Color\r\n");
<BR> }
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: textheight
<BR>功 能: 返回以像素为单位的字符串高度
<BR>用 法: int far textheight(char far *textstring);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int y = 0;
<BR> int i;
<BR> char msg[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> /* draw some text on the screen */
<BR> for (i=1; i<11; i++)
<BR> {
<BR> /* select the text style, direction,
and size */
<BR> settextstyle(TRIPLEX_FONT, HORIZ_DIR,
i);
<BR>
<P> /* create a message string */
<BR> sprintf(msg, "Size: %d", i);
<BR>
<P> /* output the message */
<BR> outtextxy(1, y, msg);
<BR>
<P> /* advance to the next text line */
<BR> y += textheight(msg);
<BR> }
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: textmode
<BR>功 能: 将屏幕设置成文本模式
<BR>用 法: void textmode(int mode);
<BR>程序例:
<BR>
<P>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> textmode(BW40);
<BR> cprintf("ABC");
<BR> getch();
<BR>
<P> textmode(C40);
<BR> cprintf("ABC");
<BR> getch();
<BR>
<P> textmode(BW80);
<BR> cprintf("ABC");
<BR> getch();
<BR>
<P> textmode(C80);
<BR> cprintf("ABC");
<BR> getch();
<BR>
<P> textmode(MONO);
<BR> cprintf("ABC");
<BR> getch();
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: textwidth
<BR>功 能: 返回以像素为单位的字符串宽度
<BR>用 法: int far textwidth(char far *textstring);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int x = 0, y = 0;
<BR> int i;
<BR> char msg[80];
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> y = getmaxy() / 2;
<BR>
<P> settextjustify(LEFT_TEXT, CENTER_TEXT);
<BR> for (i=1; i<11; i++)
<BR> {
<BR> /* select the text style, direction,
and size */
<BR> settextstyle(TRIPLEX_FONT, HORIZ_DIR,
i);
<BR>
<P> /* create a message string */
<BR> sprintf(msg, "Size: %d", i);
<BR>
<P> /* output the message */
<BR> outtextxy(x, y, msg);
<BR>
<P> /* advance to the end of the text */
<BR> x += textwidth(msg);
<BR> }
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: time
<BR>功 能: 取一天的时间
<BR>用 法: logn time(long *tloc);
<BR>程序例:
<BR>
<P>#include <time.h>
<BR>#include <stdio.h>
<BR>#include <dos.h>
<BR>
<P>int main(void)
<BR>{
<BR> time_t t;
<BR>
<P> t = time(NULL);
<BR> printf("The number of seconds since January 1, 1970 is
%ld",t);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: tmpfile
<BR>功 能: 以二进制方式打开暂存文件
<BR>用 法: FILE *tmpfile(void);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <process.h>
<BR>
<P>int main(void)
<BR>{
<BR> FILE *tempfp;
<BR>
<P> tempfp = tmpfile();
<BR> if (tempfp)
<BR> printf("Temporary file created\n");
<BR> else
<BR> {
<BR> printf("Unable to create temporary file\n");
<BR> exit(1);
<BR> }
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: tmpnam
<BR>功 能: 创建一个唯一的文件名
<BR>用 法: char *tmpnam(char *sptr);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> char name[13];
<BR>
<P> tmpnam(name);
<BR> printf("Temporary name: %s\n", name);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: tolower
<BR>功 能: 把字符转换成小写字母
<BR>用 法: int tolower(int c);
<BR>程序例:
<BR>
<P>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <ctype.h>
<BR>
<P>int main(void)
<BR>{
<BR> int length, i;
<BR> char *string = "THIS IS A STRING";
<BR>
<P> length = strlen(string);
<BR> for (i=0; i<length; i++)
<BR> {
<BR> string[i] = tolower(string[i]);
<BR> }
<BR> printf("%s\n",string);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: toupper
<BR>功 能: 把字符转换成大写字母
<BR>用 法: int toupper(int c);
<BR>程序例:
<BR>
<P>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <ctype.h>
<BR>
<P>int main(void)
<BR>{
<BR> int length, i;
<BR> char *string = "this is a string";
<BR>
<P> length = strlen(string);
<BR> for (i=0; i<length; i++)
<BR> {
<BR> string[i] = toupper(string[i]);
<BR> }
<BR>
<P> printf("%s\n",string);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: tzset
<BR>功 能: UNIX时间兼容函数
<BR>用 法: void tzset(void);
<BR>程序例:
<BR>
<P>#include <time.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> time_t td;
<BR>
<P> putenv("TZ=PST8PDT");
<BR> tzset();
<BR> time(&td);
<BR> printf("Current time = %s\n", asctime(localtime(&td)));
<BR> return 0;
<BR>}
<BR>
<BR>
<hr color="#EE9B73" size="1" width="94%">
</TD>
<TD CLASS="tt3" VALIGN="bottom" width="8%" bgcolor="#e0e0e0"><strong><A HREF="038.htm">后一页</A><BR>
<A HREF="036.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
</TR>
</table>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -