找回密码

碧海潮声大学生网

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

c语言函数大全

[复制链接]
201#
 楼主| 发表于 2006-7-13 00:44 | 只看该作者
函数名: poke
功 能: 存值到一个给定存储单元
用 法: void poke(int segment, int offset, int value);
程序例:
#include
#include
int main(void)
{
clrscr();
cprintf("Make sure the scroll lock key is off and press any key\r
");
getch();
poke(0x0000,0x0417,16);
cprintf("The scroll lock is now on\r
");
return 0;
}
202#
 楼主| 发表于 2006-7-13 00:44 | 只看该作者
函数名: pokeb
功 能: 存值到一个给定存储单元
用 法: void pokeb(int segment, int offset, char value);
程序例:
#include
#include
int main(void)
{
clrscr();
cprintf("Make sure the scroll lock key is off and press any key\r
");
getch();
pokeb(0x0000,0x0417,16);
cprintf("The scroll lock is now on\r
");
return 0;
}
203#
 楼主| 发表于 2006-7-13 00:45 | 只看该作者
函数名: poly
功 能: 根据参数产生一个多项式
用 法: double poly(double x, int n, double c[]);
程序例:
#include
#include
/* polynomial: x**3 - 2x**2 + 5x - 1 */
int main(void)
{
double array[] = { -1.0, 5.0, -2.0, 1.0 };
double result;
result = poly(2.0, 3, array);
printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf
",
result);
return 0;
}
204#
 楼主| 发表于 2006-7-13 00:45 | 只看该作者
函数名: pow
功 能: 指数函数(x的y次方)
用 法: double pow(double x, double y);
程序例:
#include
#include
int main(void)
{
double x = 2.0, y = 3.0;
printf("%lf raised to %lf is %lf
", x, y, pow(x, y));
return 0;
}
205#
 楼主| 发表于 2006-7-13 00:45 | 只看该作者
函数名: pow10
功 能: 指数函数(10的p次方)
用 法: double pow10(int p);
程序例:
#include
#include
int main(void)
{
double p = 3.0;
printf("Ten raised to %lf is %lf
", p, pow10(p));
return 0;
}
206#
 楼主| 发表于 2006-7-13 00:46 | 只看该作者
函数名: printf
功 能: 产生格式化输出的函数
用 法: int printf(char *format...);
程序例:
#include
#include
#define I 555
#define R 5.5
int main(void)
{
int i,j,k,l;
char buf[7];
char *prefix = buf;
char tp[20];
printf("prefix 6d 6o 8x 10.2e "
"10.2f
");
strcpy(prefix,"%");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
for (k = 0; k < 2; k++)
for (l = 0; l < 2; l++)
{
if (i==0) strcat(prefix,"-");
if (j==0) strcat(prefix,"+");
if (k==0) strcat(prefix,"#");
if (l==0) strcat(prefix,"0");
printf("%5s |",prefix);
strcpy(tp,prefix);
strcat(tp,"6d |");
printf(tp,I);
strcpy(tp,"");
strcpy(tp,prefix);
strcat(tp,"6o |");
printf(tp,I);
strcpy(tp,"");
strcpy(tp,prefix);
strcat(tp,"8x |");
printf(tp,I);
strcpy(tp,"");
strcpy(tp,prefix);
strcat(tp,"10.2e |");
printf(tp,R);
strcpy(tp,prefix);
strcat(tp,"10.2f |");
printf(tp,R);
printf("
");
strcpy(prefix,"%");
}
}
return 0;
}
207#
 楼主| 发表于 2006-7-13 00:46 | 只看该作者
函数名: putc
功 能: 输出一字符到指定流中
用 法: int putc(int ch, FILE *stream);
程序例:
#include
int main(void)
{
char msg[] = "Hello world
";
int i = 0;
while (msg)
putc(msg[i++], stdout);
return 0;
}
208#
 楼主| 发表于 2006-7-13 00:46 | 只看该作者
函数名: putch
功 能: 输出字符到控制台
用 法: int putch(int ch);
程序例:
#include
#include
int main(void)
{
char ch = 0;
printf("Input a string:");
while ((ch != &#39;\r&#39;))
{
ch = getch();
putch(ch);
}
return 0;
}
209#
 楼主| 发表于 2006-7-13 00:46 | 只看该作者
函数名: putchar
功 能: 在stdout上输出字符
用 法: int putchar(int ch);
程序例:
#include
/* define some box-drawing characters */
#define LEFT_TOP 0xDA
#define RIGHT_TOP 0xBF
#define HORIZ 0xC4
#define VERT 0xB3
#define LEFT_BOT 0xC0
#define RIGHT_BOT 0xD9
int main(void)
{
char i, j;
/* draw the top of the box */
putchar(LEFT_TOP);
for (i=0; i<10; i++)
putchar(HORIZ);
putchar(RIGHT_TOP);
putchar(&#39;
&#39;);
/* draw the middle */
for (i=0; i<4; i++)
{
putchar(VERT);
for (j=0; j<10; j++)
putchar(&#39; &#39;);
putchar(VERT);
putchar(&#39;
&#39;);
}
/* draw the bottom */
putchar(LEFT_BOT);
for (i=0; i<10; i++)
putchar(HORIZ);
putchar(RIGHT_BOT);
putchar(&#39;
&#39;);
return 0;
}
210#
 楼主| 发表于 2006-7-13 00:47 | 只看该作者
函数名: putenv
功 能: 把字符串加到当前环境中
用 法: int putenv(char *envvar);
程序例:
#include
#include
#include
#include
#include
int main(void)
{
char *path, *ptr;
int i = 0;
/* get the current path environment */
ptr = getenv("PATH");
/* set up new path */
path = malloc(strlen(ptr)+15);
strcpy(path,"PATH=");
strcat(path,ptr);
strcat(path,";c:\\temp");
/* replace the current path and display current environment */
putenv(path);
while (environ)
printf("%s
",environ[i++]);
return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

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

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