韩冰 发表于 2004-10-4 02:54

函数大全(t开头)

<P><FONT color=#ff0000>函数名: tan </FONT>
功 能: 正切函数
用 法: double tan(double x);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <MATH.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
double result, x; </FONT></P>
<P><FONT color=#0000ff>x = 0.5;
result = tan(x);
printf("The tan of %lf is %lf\n", x, result);
return 0;
} </FONT>


</P>
<P><FONT color=#ff0000>函数名: tanh</FONT>
功 能: 双曲正切函数
用 法: double tanh(double x);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <MATH.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
double result, x; </FONT></P>
<P><FONT color=#0000ff>x = 0.5;
result = tanh(x);
printf("The hyperbolic tangent of %lf is %lf\n", x, result);
return 0;
}


</FONT>
</P>
<P><FONT color=#ff0000>函数名: tell </FONT>
功 能: 取文件指针的当前位置
用 法: long tell(int handle);
程序例: </P>
<P><FONT color=#0000ff>#include <STRING.H>
#include <STDIO.H>
#include <FCNTL.H>
#include <IO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int handle;
char msg[] = "Hello world"; </FONT></P>
<P><FONT color=#0000ff>if ((handle = open("TEST.$$$", O_CREAT | O_TEXT | O_APPEND)) == -1)
{
perror("Error:");
return 1;
}
write(handle, msg, strlen(msg));
printf("The file pointer is at byte %ld\n", tell(handle));
close(handle);
return 0;
}
</FONT>


</P>
<P><FONT color=#ff0000>函数名: textattr </FONT>
功 能: 设置文本属性
用 法: void textattr(int attribute);
程序例: </P>
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int i; </FONT></P>
<P><FONT color=#0000ff>clrscr();
for (i=0; i&lt;9; i++)
{
textattr(i + ((i+1) &lt;&lt; 4));
cprintf("This is a test\r\n");
} </FONT></P>
<P><FONT color=#0000ff>return 0;
} </FONT>


</P>
<P><FONT color=#ff0000>函数名: textbackground </FONT>
功 能: 选择新的文本背景颜色
用 法: void textbackground(int color);
程序例: </P>
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int i, j; </FONT></P>
<P><FONT color=#0000ff>clrscr();
for (i=0; i&lt;9; i++)
{
for (j=0; j&lt;80; j++)
cprintf("C");
cprintf("\r\n");
textcolor(i+1);
textbackground(i);
} </FONT></P>
<P><FONT color=#0000ff>return 0;
}

</FONT>
</P>
<P><FONT color=#ff0000>函数名: textcolor </FONT>
<FONT color=#000000>功 能: 在文本模式中选择新的字符颜色
用 法: void textcolor(int color);
程序例: </FONT><FONT color=#0000ff>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int i; </FONT></P>
<P><FONT color=#0000ff>for (i=0; i&lt;15; i++)
{
textcolor(i);
cprintf("Foreground Color\r\n");
} </FONT></P>
<P><FONT color=#0000ff>return 0;
}


</FONT></P>
<P><FONT color=#ff0000>函数名: textheight </FONT><FONT color=#0000ff>
<FONT color=#000000>功 能: 返回以像素为单位的字符串高度
用 法: int far textheight(char far *textstring);
程序例: </FONT></FONT></P>
<P><FONT color=#0000ff>#include <GRAPHICS.H>
#include <STDLIB.H>
#include <STDIO.H>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int y = 0;
int i;
char msg; </FONT></P>
<P><FONT color=#0000ff>/* initialize graphics and local variables */
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
<P><FONT color=#0000ff>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </FONT></P>
<P><FONT color=#0000ff>/* draw some text on the screen */
for (i=1; i&lt;11; i++)
{
/* select the text style, direction, and size */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, i); </FONT></P>
<P><FONT color=#0000ff>/* create a message string */
sprintf(msg, "Size: %d", i); </FONT></P>
<P><FONT color=#0000ff>/* output the message */
outtextxy(1, y, msg); </FONT></P>
<P><FONT color=#0000ff>/* advance to the next text line */
y += textheight(msg);
} </FONT></P>
<P><FONT color=#0000ff>/* clean up */
getch();
closegraph();
return 0;
} </FONT>


</P>
<P><FONT color=#ff0000>函数名: textmode </FONT>
功 能: 将屏幕设置成文本模式
用 法: void textmode(int mode);
程序例: </P>
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
textmode(BW40);
cprintf("ABC");
getch(); </FONT></P>
<P><FONT color=#0000ff>textmode(C40);
cprintf("ABC");
getch(); </FONT></P>
<P><FONT color=#0000ff>textmode(BW80);
cprintf("ABC");
getch(); </FONT></P>
<P><FONT color=#0000ff>textmode(C80);
cprintf("ABC");
getch(); </FONT></P>
<P><FONT color=#0000ff>textmode(MONO);
cprintf("ABC");
getch(); </FONT></P>
<P><FONT color=#0000ff>return 0;
}

</FONT></P>
<P><FONT color=#ff0000>函数名: textwidth </FONT>
功 能: 返回以像素为单位的字符串宽度
用 法: int far textwidth(char far *textstring);
程序例: </P>
<P><FONT color=#0000ff>#include <GRAPHICS.H>
#include <STDLIB.H>
#include <STDIO.H>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int x = 0, y = 0;
int i;
char msg; </FONT></P>
<P><FONT color=#0000ff>/* initialize graphics and local variables */
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
<P><FONT color=#0000ff>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} </FONT></P>
<P><FONT color=#0000ff>y = getmaxy() / 2; </FONT></P>
<P><FONT color=#0000ff>settextjustify(LEFT_TEXT, CENTER_TEXT);
for (i=1; i&lt;11; i++)
{
/* select the text style, direction, and size */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, i); </FONT></P>
<P><FONT color=#0000ff>/* create a message string */
sprintf(msg, "Size: %d", i); </FONT></P>
<P><FONT color=#0000ff>/* output the message */
outtextxy(x, y, msg); </FONT></P>
<P><FONT color=#0000ff>/* advance to the end of the text */
x += textwidth(msg);
} </FONT></P>
<P><FONT color=#0000ff>/* clean up */
getch();
closegraph();
return 0;
}
</FONT>
</P>
<P><FONT color=#ff0000>函数名: time </FONT>
功 能: 取一天的时间
用 法: logn time(long *tloc);
程序例: </P>
<P><FONT color=#0000ff>#include <TIME.H>
#include <STDIO.H>
#include <DOS.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
time_t t; </FONT></P>
<P><FONT color=#0000ff>t = time(NULL);
printf("The number of seconds since January 1, 1970 is %ld",t);
return 0;
}</FONT>


</P>
<P><FONT color=#ff0000>函数名: tmpfile </FONT>
功 能: 以二进制方式打开暂存文件
用 法: FILE *tmpfile(void);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <PROCESS.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
FILE *tempfp; </FONT></P>
<P><FONT color=#0000ff>tempfp = tmpfile();
if (tempfp)
printf("Temporary file created\n");
else
{
printf("Unable to create temporary file\n");
exit(1);
} </FONT></P>
<P><FONT color=#0000ff>return 0;
}

</FONT>
</P>
<P><FONT color=#ff0000>函数名: tmpnam </FONT>
功 能: 创建一个唯一的文件名
用 法: char *tmpnam(char *sptr);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
char name; </FONT></P>
<P><FONT color=#0000ff>tmpnam(name);
printf("Temporary name: %s\n", name);
return 0;
}


</FONT></P>
<P><FONT color=#ff0000>函数名: tolower </FONT>
功 能: 把字符转换成小写字母
用 法: int tolower(int c);
程序例: </P>
<P><FONT color=#0000ff>#include <STRING.H>
#include <STDIO.H>
#include <CTYPE.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int length, i;
char *string = "THIS IS A STRING"; </FONT></P>
<P><FONT color=#0000ff>length = strlen(string);
for (i=0; i<LENGTH; <br i++)> {
string = tolower(string);
}
printf("%s\n",string); </FONT></P>
<P><FONT color=#0000ff>return 0;
}
</FONT>
</P>
<P><FONT color=#ff0000>函数名: toupper </FONT>
功 能: 把字符转换成大写字母
用 法: int toupper(int c);
程序例: </P>
<P><FONT color=#0000ff>#include <STRING.H>
#include <STDIO.H>
#include <CTYPE.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int length, i;
char *string = "this is a string"; </FONT></P>
<P><FONT color=#0000ff>length = strlen(string);
for (i=0; i<LENGTH; <br i++)> {
string = toupper(string);
} </FONT></P>
<P><FONT color=#0000ff>printf("%s\n",string); </FONT></P>
<P><FONT color=#0000ff>return 0;
} </FONT>

</P>
<P><FONT color=#ff0000>函数名: tzset </FONT>
功 能: UNIX时间兼容函数
用 法: void tzset(void);
程序例: </P>
<P><FONT color=#0000ff>#include <TIME.H>
#include <STDLIB.H>
#include <STDIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
time_t td; </FONT></P>
<P><FONT color=#0000ff>putenv("TZ=PST8PDT");
tzset();
time(&amp;td);
printf("Current time = %s\n", asctime(localtime(&amp;td)));
return 0;
} </FONT></P>
页: [1]
查看完整版本: 函数大全(t开头)