找回密码

碧海潮声大学生网

楼主: 墙角野猫
打印 上一主题 下一主题

c语言函数大全

[复制链接]
321#
 楼主| 发表于 2006-7-13 01:25 | 只看该作者
函数名: 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;
}
322#
 楼主| 发表于 2006-7-13 01:25 | 只看该作者
函数名: 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
", 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;
}
323#
 楼主| 发表于 2006-7-13 01:26 | 只看该作者
函数名: time
功 能: 取一天的时间
用 法: logn time(long *tloc);
程序例:
#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;
}
324#
 楼主| 发表于 2006-7-13 01:33 | 只看该作者
继续
325#
 楼主| 发表于 2006-7-13 01:33 | 只看该作者
函数名: tmpfile
功 能: 以二进制方式打开暂存文件
用 法: FILE *tmpfile(void);
程序例:
#include
#include
int main(void)
{
FILE *tempfp;
tempfp = tmpfile();
if (tempfp)
printf("Temporary file created
");
else
{
printf("Unable to create temporary file
");
exit(1);
}
return 0;
}
326#
 楼主| 发表于 2006-7-13 01:34 | 只看该作者
函数名: tmpnam
功 能: 创建一个唯一的文件名
用 法: char *tmpnam(char *sptr);
程序例:
#include
int main(void)
{
char name[13];
tmpnam(name);
printf("Temporary name: %s
", name);
return 0;
}
327#
 楼主| 发表于 2006-7-13 01:34 | 只看该作者
函数名: 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 = tolower(string);
}
printf("%s
",string);
return 0;
}
328#
 楼主| 发表于 2006-7-13 01:34 | 只看该作者
函数名: 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 = toupper(string);
}
printf("%s
",string);
return 0;
}
329#
 楼主| 发表于 2006-7-13 01:34 | 只看该作者
函数名: tzset
功 能: UNIX时间兼容函数
用 法: void tzset(void);
程序例:
#include
#include
#include
int main(void)
{
time_t td;
putenv("TZ=PST8PDT");
tzset();
time(&td);
printf("Current time = %s
", asctime(localtime(&td)));
return 0;
}
330#
 楼主| 发表于 2006-7-13 01:35 | 只看该作者
函数名: ultoa
功 能: 转换一个无符号长整型数为字符串
用 法: char *ultoa(unsigned long value, char *string, int radix);
程序例:
#include
#include
int main( void )
{
unsigned long lnumber = 3123456789L;
char string[25];
ultoa(lnumber,string,10);
printf("string = %s unsigned long = %lu
",string,lnumber);
return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表