C语言函数大全(t开头)
当前位置:以往代写 > C/C++ 教程 >C语言函数大全(t开头)
2019-06-13

C语言函数大全(t开头)

C语言函数大全(t开头)

副标题#e#

函数名: tell

成果: 取文件指针的当前位置

用法: long tell(int handle);

措施例:

#include
#include
#include
#include
int main(void)
{
int handle;
char msg[] = "Hello world";
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;
}

函数名: textattr

成果: 配置文本属性

用法: void textattr(int attribute);

措施例:

#include
int main(void)
{
int i;
clrscr();
for (i=0; i<9; i++)
{
textattr(i + ((i+1) << 4));
cprintf("This is a test\r\n");
}
return 0;
}


#p#副标题#e#

函数名: textbackground

成果: 选择新的文本配景颜色

用法: void textbackground(int color);

措施例:

#include
int main(void)
{
int i, j;
clrscr();
for (i=0; i<9; i++)
{
for (j=0; j<80; j++)
cprintf("C");
cprintf("\r\n");
textcolor(i+1);
textbackground(i);
}
return 0;
}

函数名: textcolor

成果: 在文本模式中选择新的字符颜色

用法: void textcolor(int color);

措施例:

#include
int main(void)
{
int i;
for (i=0; i<15; i++)
{
textcolor(i);
cprintf("Foreground Color\r\n");
}
return 0;
}

#p#副标题#e#

函数名: textheight

成果: 返回以像素为单元的字符串高度

用法: int far textheight(char far *textstring);

措施例:

#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int y = 0;
int i;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* 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 */
}
/* draw some text on the screen */
for (i=1; i<11; i++)
{
/* select the text style, direction, and size */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, i);
/* create a message string */
sprintf(msg, "Size: %d", i);
/* output the message */
outtextxy(1, y, msg);
/* advance to the next text line */
y += textheight(msg);
}
/* clean up */
getch();
closegraph();
return 0;
}

#p#副标题#e#

函数名: textmode

成果: 将屏幕配置成文本模式

用法: void textmode(int mode);

措施例:

#include
int main(void)
{
textmode(BW40);
cprintf("ABC");
getch();
textmode(C40);
cprintf("ABC");
getch();
textmode(BW80);
cprintf("ABC");
getch();
textmode(C80);
cprintf("ABC");
getch();
textmode(MONO);
cprintf("ABC");
getch();
return 0;
}

函数名: textwidth

成果: 返回以像素为单元的字符串宽度

用法: int far textwidth(char far *textstring);

措施例:

#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int x = 0, y = 0;
int i;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* 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 */
}
y = getmaxy() / 2;
settextjustify(LEFT_TEXT, CENTER_TEXT);
for (i=1; i<11; i++)
{
/* select the text style, direction, and size */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, i);
/* create a message string */
sprintf(msg, "Size: %d", i);
/* output the message */
outtextxy(x, y, msg);
/* advance to the end of the text */
x += textwidth(msg);
}
/* clean up */
getch();
closegraph();
return 0;
}

#p#副标题#e#

函数名: time

成果: 取一天的时间

用法: logn time(long *tloc);

措施例:

#p#分页标题#e#

#include
#include
#include
int main(void)
{
time_t t;
t = time(NULL);
printf("The number of seconds since January 1, 1970 is %ld",t);
return 0;
}

函数名: tmpfile

成果: 以二进制方法打开暂存文件

用法: FILE *tmpfile(void);

措施例:

#include
#include
int main(void)
{
FILE *tempfp;
tempfp = tmpfile();
if (tempfp)
printf("Temporary file created\n");
else
{
printf("Unable to create temporary file\n");
exit(1);
}
return 0;
}

#p#副标题#e#

函数名: tmpnam

成果: 建设一个独一的文件名

用法: char *tmpnam(char *sptr);

措施例:

#include
int main(void)
{
char name[13];
tmpnam(name);
printf("Temporary name: %s\n", name);
return 0;
}

函数名: tolower

成果: 把字符转换成小写字母

用法: int tolower(int c);

措施例:

#include
#include
#include
int main(void)
{
int length, i;
char *string = "THIS IS A STRING";
length = strlen(string);
for (i=0; i {
string[i] = tolower(string[i]);
}
printf("%s\n",string);
return 0;
}

#p#副标题#e#

函数名: toupper

成果: 把字符转换成大写字母

用法: int toupper(int c);

措施例:

#include
#include
#include
int main(void)
{
int length, i;
char *string = "this is a string";
length = strlen(string);
for (i=0; i {
string[i] = toupper(string[i]);
}
printf("%s\n",string);
return 0;
}

函数名: tzset

成果: UNIX时间兼容函数

用法: void tzset(void);

措施例:

#include
#include
#include
int main(void)
{
time_t td;
putenv("TZ=PST8PDT");
tzset();
time(&td);
printf("Current time = %s\n", asctime(localtime(&td)));
return 0;
}

    关键字:

在线提交作业