?? 王大剛--c語言編程寶典--t.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/037.htm -->
<HTML><HEAD><TITLE>王大剛-->C語言編程寶典-->T</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大剛 C語言編程寶典 T" name=keywords>
<META content="王大剛 - C語言編程寶典 - T" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋體"
}
.tt2 {
FONT: 12pt/15pt "宋體"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/038.htm">后一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/036.htm">前一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目錄</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首頁</A><BR></STRONG></TD>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷體_GB2312
color=#ff6666>T</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<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 width="94%" color=#ee9b73 SIZE=1>
</TD>
<TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/038.htm">后一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/036.htm">前一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目錄</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首頁</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -