找回密码

碧海潮声大学生网

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

c语言函数大全

[复制链接]
311#
 楼主| 发表于 2006-7-13 01:22 | 只看该作者
函数名: strupr
功 能: 将串中的小写字母转换为大写字母
用 法: char *strupr(char *str);
程序例:
#include
#include
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;
/* converts string to upper case characters */
ptr = strupr(string);
printf("%s
", ptr);
return 0;
}
312#
 楼主| 发表于 2006-7-13 01:23 | 只看该作者
函数名: swab
功 能: 交换字节
用 法: void swab (char *from, char *to, int nbytes);
程序例:
#include
#include
#include
char source[15] = "rFna koBlrna d";
char target[15];
int main(void)
{
swab(source, target, strlen(source));
printf("This is target: %s
", target);
return 0;
}
313#
 楼主| 发表于 2006-7-13 01:23 | 只看该作者
函数名: system
功 能: 发出一个DOS命令
用 法: int system(char *command);
程序例:
#include
#include
int main(void)
{
printf("About to spawn command.com and run a DOS command
");
system("dir");
return 0;
}
314#
 楼主| 发表于 2006-7-13 01:23 | 只看该作者
函数名: tan
功 能: 正切函数
用 法: double tan(double x);
程序例:
#include
#include
int main(void)
{
double result, x;
x = 0.5;
result = tan(x);
printf("The tan of %lf is %lf
", x, result);
return 0;
}
315#
 楼主| 发表于 2006-7-13 01:23 | 只看该作者
函数名: tanh
功 能: 双曲正切函数
用 法: double tanh(double x);
程序例:
#include
#include
int main(void)
{
double result, x;
x = 0.5;
result = tanh(x);
printf("The hyperbolic tangent of %lf is %lf
", x, result);
return 0;
}
316#
 楼主| 发表于 2006-7-13 01:24 | 只看该作者
函数名: 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
", tell(handle));
close(handle);
return 0;
}
317#
 楼主| 发表于 2006-7-13 01:24 | 只看该作者
函数名: 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
");
}
return 0;
}
318#
 楼主| 发表于 2006-7-13 01:24 | 只看该作者
函数名: 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
");
textcolor(i+1);
textbackground(i);
}
return 0;
}
319#
 楼主| 发表于 2006-7-13 01:24 | 只看该作者
函数名: textcolor
功 能: 在文本模式中选择新的字符颜色
用 法: void textcolor(int color);
程序例:
#include
int main(void)
{
int i;
for (i=0; i<15; i++)
{
textcolor(i);
cprintf("Foreground Color\r
");
}
return 0;
}
320#
 楼主| 发表于 2006-7-13 01:25 | 只看该作者
函数名: 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
", 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;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

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

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