当前位置:文档之家› C语言函数大全(A)

C语言函数大全(A)

函数名: abort

功能: 异常终止一个进程

用法: void abort(void);

程序例:

#include

#include

int main(void)

{

printf("Calling abort()\n");

abort();

return 0; /* This is never reached */

}

函数名: abs

功能: 求整数的绝对值

用法: int abs(int i);

程序例:

#include

#include

int main(void)

{

int number = -1234;

printf("number: %d absolute value: %d\n", number, abs(number)); return 0;

}

函数名: absread, abswirte

功能: 绝对磁盘扇区读、写数据

用法: int absread(int drive, int nsects, int sectno, void *buffer);

int abswrite(int drive, int nsects, in tsectno, void *buffer);

程序例:

/* absread example */

#include

#include

#include

#include

int main(void)

{

int i, strt, ch_out, sector;

char buf[512];

printf("Insert a diskette into drive A and press any key\n"); getch();

sector = 0;

if (absread(0, 1, sector, &buf) != 0)

{

perror("Disk problem");

exit(1);

}

printf("Read OK\n");

strt = 3;

for (i=0; i<80; i++)

{

ch_out = buf[strt+i];

putchar(ch_out);

}

printf("\n");

return(0);

}

函数名: access

功能: 确定文件的访问权限

用法: int access(const char *filename, int amode);

程序例:

#include

#include

int file_exists(char *filename);

int main(void)

{

printf("Does NOTEXIST.FIL exist: %s\n",

file_exists("NOTEXISTS.FIL") ? "YES" : "NO");

return 0;

}

int file_exists(char *filename)

{

return (access(filename, 0) == 0);

}

函数名: acos

功能: 反余弦函数

用法: double acos(double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 0.5;

result = acos(x);

printf("The arc cosine of %lf is %lf\n", x, result); return 0;

}

函数名: allocmem

功能: 分配DOS存储段

用法: int allocmem(unsigned size, unsigned *seg);

程序例:

#include

#include

#include

int main(void)

{

unsigned int size, segp;

int stat;

size = 64; /* (64 x 16) = 1024 bytes */

stat = allocmem(size, &segp);

if (stat == -1)

printf("Allocated memory at segment: %x\n", segp); else

printf("Failed: maximum number of paragraphs available is %u\n", stat);

return 0;

}

函数名: arc

功能: 画一弧线

用法: void far arc(int x, int y, int stangle, int endangle, int radius);

程序例:

#include

#include

#include

#include

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

int stangle = 45, endangle = 135;

int radius = 100;

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult(); /* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* draw arc */

arc(midx, midy, stangle, endangle, radius);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: asctime

功能: 转换日期和时间为ASCII码

用法: char *asctime(const struct tm *tblock);

程序例:

#include

#include

#include

int main(void)

{

struct tm t;

char str[80];

/* sample loading of tm structure */

t.tm_sec = 1; /* Seconds */

t.tm_min = 30; /* Minutes */

t.tm_hour = 9; /* Hour */

t.tm_mday = 22; /* Day of the Month */

t.tm_mon = 11; /* Month */

t.tm_year = 56; /* Year - does not include century */

t.tm_wday = 4; /* Day of the week */

t.tm_yday = 0; /* Does not show in asctime */

t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ /* converts structure to null terminated

string */

strcpy(str, asctime(&t));

printf("%s\n", str);

return 0;

}

函数名: asin

功能: 反正弦函数

用法: double asin(double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 0.5;

result = asin(x);

printf("The arc sin of %lf is %lf\n", x, result);

return(0);

}

函数名: assert

功能: 测试一个条件并可能使程序终止

用法: void assert(int test);

程序例:

#include

#include

#include

struct ITEM {

int key;

int value;

};

/* add item to list, make sure list is not null */ void additem(struct ITEM *itemptr) {

assert(itemptr != NULL);

/* add item to list */

}

int main(void)

{

additem(NULL);

return 0;

}

函数名: atan

功能: 反正切函数

用法: double atan(double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 0.5;

result = atan(x);

printf("The arc tangent of %lf is %lf\n", x, result);

return(0);

}

函数名: atan2

功能: 计算Y/X的反正切值

用法: double atan2(double y, double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 90.0, y = 45.0;

result = atan2(y, x);

printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);

return 0;

}

函数名: atexit

功能: 注册终止函数

用法: int atexit(atexit_t func);

程序例:

#include

#include

void exit_fn1(void)

{

printf("Exit function #1 called\n");

}

void exit_fn2(void)

{

printf("Exit function #2 called\n");

}

int main(void)

{

/* post exit function #1 */

atexit(exit_fn1);

/* post exit function #2 */

atexit(exit_fn2);

return 0;

}

函数名: atof

功能: 把字符串转换成浮点数

用法: double atof(const char *nptr);

程序例:

#include

#include

int main(void)

{

float f;

char *str = "12345.67";

f = atof(str);

printf("string = %s float = %f\n", str, f);

return 0;

}

函数名: atoi

功能: 把字符串转换成长整型数

用法: int atoi(const char *nptr);

程序例:

#include

#include

int main(void)

{

int n;

char *str = "12345.67";

n = atoi(str);

printf("string = %s integer = %d\n", str, n);

return 0;

}

函数名: atol

功能: 把字符串转换成长整型数

用法: long atol(const char *nptr);

程序例:

#include

#include

int main(void)

{

long l;

char *str = "98765432";

l = atol(lstr);

printf("string = %s integer = %ld\n", str, l);

return(0);

}

函数名: abort

功能: 异常终止一个进程

用法: void abort(void);

程序例:

#include

#include

int main(void)

{

printf("Calling abort()\n");

abort();

return 0; /* This is never reached */

}

函数名: abs

功能: 求整数的绝对值

用法: int abs(int i);

程序例:

#include

#include

int main(void)

{

int number = -1234;

printf("number: %d absolute value: %d\n", number, abs(number)); return 0;

}

函数名: absread, abswirte

功能: 绝对磁盘扇区读、写数据

用法: int absread(int drive, int nsects, int sectno, void *buffer);

int abswrite(int drive, int nsects, in tsectno, void *buffer);

程序例:

/* absread example */

#include

#include

#include

#include

int main(void)

{

int i, strt, ch_out, sector;

char buf[512];

printf("Insert a diskette into drive A and press any key\n"); getch();

sector = 0;

if (absread(0, 1, sector, &buf) != 0)

{

perror("Disk problem");

exit(1);

}

printf("Read OK\n");

strt = 3;

for (i=0; i<80; i++)

{

ch_out = buf[strt+i];

putchar(ch_out);

}

printf("\n");

return(0);

}

函数名: access

功能: 确定文件的访问权限

用法: int access(const char *filename, int amode);

程序例:

#include

#include

int file_exists(char *filename);

int main(void)

{

printf("Does NOTEXIST.FIL exist: %s\n",

file_exists("NOTEXISTS.FIL") ? "YES" : "NO");

return 0;

}

int file_exists(char *filename)

{

return (access(filename, 0) == 0);

}

函数名: acos

功能: 反余弦函数

用法: double acos(double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 0.5;

result = acos(x);

printf("The arc cosine of %lf is %lf\n", x, result);

return 0;

}

函数名: allocmem

功能: 分配DOS存储段

用法: int allocmem(unsigned size, unsigned *seg);

程序例:

#include

#include

#include

int main(void)

{

unsigned int size, segp;

int stat;

size = 64; /* (64 x 16) = 1024 bytes */

stat = allocmem(size, &segp);

if (stat == -1)

printf("Allocated memory at segment: %x\n", segp);

else

printf("Failed: maximum number of paragraphs available is %u\n", stat);

return 0;

}

函数名: arc

功能: 画一弧线

用法: void far arc(int x, int y, int stangle, int endangle, int radius); 程序例:

#include

#include

#include

#include

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

int stangle = 45, endangle = 135;

int radius = 100;

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "");

/* read result of initialization */

errorcode = graphresult(); /* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* draw arc */

arc(midx, midy, stangle, endangle, radius);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: asctime

功能: 转换日期和时间为ASCII码

用法: char *asctime(const struct tm *tblock);

程序例:

#include

#include

#include

int main(void)

{

struct tm t;

char str[80];

/* sample loading of tm structure */

t.tm_sec = 1; /* Seconds */

t.tm_min = 30; /* Minutes */

t.tm_hour = 9; /* Hour */

t.tm_mday = 22; /* Day of the Month */

t.tm_mon = 11; /* Month */

t.tm_year = 56; /* Year - does not include century */

t.tm_wday = 4; /* Day of the week */

t.tm_yday = 0; /* Does not show in asctime */

t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ /* converts structure to null terminated

string */

strcpy(str, asctime(&t));

printf("%s\n", str);

return 0;

}

函数名: asin

功能: 反正弦函数

用法: double asin(double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 0.5;

result = asin(x);

printf("The arc sin of %lf is %lf\n", x, result);

return(0);

}

函数名: assert

功能: 测试一个条件并可能使程序终止

用法: void assert(int test);

程序例:

#include

#include

#include

struct ITEM {

int key;

int value;

};

/* add item to list, make sure list is not null */ void additem(struct ITEM *itemptr) {

assert(itemptr != NULL);

/* add item to list */

}

int main(void)

{

additem(NULL);

return 0;

函数名: atan

功能: 反正切函数

用法: double atan(double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 0.5;

result = atan(x);

printf("The arc tangent of %lf is %lf\n", x, result);

return(0);

}

函数名: atan2

功能: 计算Y/X的反正切值

用法: double atan2(double y, double x);

程序例:

#include

#include

int main(void)

{

double result;

double x = 90.0, y = 45.0;

result = atan2(y, x);

printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);

return 0;

}

函数名: atexit

功能: 注册终止函数

用法: int atexit(atexit_t func);

程序例:

#include

#include

void exit_fn1(void)

{

printf("Exit function #1 called\n");

}

void exit_fn2(void)

{

printf("Exit function #2 called\n");

}

int main(void)

{

/* post exit function #1 */

atexit(exit_fn1);

/* post exit function #2 */

atexit(exit_fn2);

return 0;

}

函数名: atof

功能: 把字符串转换成浮点数

用法: double atof(const char *nptr);

程序例:

#include

#include

int main(void)

{

float f;

char *str = "12345.67";

f = atof(str);

printf("string = %s float = %f\n", str, f);

return 0;

}

函数名: atoi

功能: 把字符串转换成长整型数

用法: int atoi(const char *nptr);

程序例:

#include

#include

int main(void)

{

int n;

char *str = "12345.67";

n = atoi(str);

printf("string = %s integer = %d\n", str, n);

return 0;

}

函数名: atol

功能: 把字符串转换成长整型数

用法: long atol(const char *nptr);

程序例:

#include

#include

int main(void)

{

long l;

char *str = "98765432";

l = atol(lstr);

printf("string = %s integer = %ld\n", str, l);

return(0);

}

C语言常用函数

C语言的常用库函数 函数1。absread()读磁盘绝对扇区函数 原形:int absread(int drive,int num,int sectnum,void *buf) 功能:从drive指定的驱动器磁盘上,sectnum指定的逻辑扇区号开始读取(通过DOS中断0x25读取)num 个(最多64K个)扇区的内容,储存于buf所指的缓冲区中。 参数:drive=0对应A盘,drive=1对应B盘。 返回值:0:成功;-1:失败。 头文件:dos.h 函数2。abswrite()写磁盘绝对扇区函数 原形:int abswrite(int drive,int nsects,int lsect,void *buffer) drive=0(A驱动器)、1(B驱动器)、 nsects=要写的扇区数(最多64K个); lsect=起始逻辑扇区号; buffer=要写入数据的内存起始地址。 功能:将指定内容写入(调用DOS中断0x26)磁盘上的指定扇区,即使写入的地方是磁盘的逻辑结构、文件、FAT表和目录结构所在的扇区,也照常进行。 返回值:0:成功;-1:失败。 头文件:dos.h 函数3。atof()将字符串转换成浮点数的函数 原形:double atof(const char *s) 功能:把s所指向的字符串转换成double类型。 s格式为:符号数字.数字E符号数字 返回值:字符串的转换值。 头文件:math.h、stdlib.h 函数4。atoi()将字符串转换成整型数的函数 原形:int atoi(const char *s) 功能:把s所指向的字符串转换成int类型。 s格式为:符号数字 返回值:字符串的转换值。若出错则返回0。 头文件:stdlib.h 函数5。atol()将字符串转换成长整型数的函数 原形:long atol(const char *s)

C语言常用函数手册

1.分类函数,所在函数库为ctype.h int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0 int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9'),返回非0值,否则返回0 int isascii(int ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0 int iscntrl(int ch) 若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F) 返回非0值,否则返回0 int isdigit(int ch) 若ch是数字('0'-'9')返回非0值,否则返回0 int isgraph(int ch) 若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0 int islower(int ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0 int isprint(int ch) 若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0 int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0 int isspace(int ch) 若ch是空格(' '),水平制表符('\t'),回车符('\r'), 走纸换行('\f'),垂直制表符('\v'),换行符('\n') 返回非0值,否则返回0 int isupper(int ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0 int isxdigit(int ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值, 否则返回0 int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z') int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z') 2.数学函数,所在函数库为math.h、stdlib.h、string.h、float.h int abs(int i) 返回整型参数i的绝对值 double cabs(struct complex znum) 返回复数znum的绝对值 double fabs(double x) 返回双精度参数x的绝对值 long labs(long n) 返回长整型参数n的绝对值 double exp(double x) 返回指数函数ex的值 double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中double ldexp(double value,int exp); 返回value*2exp的值 double log(double x) 返回logex的值 double log10(double x) 返回log10x的值 double pow(double x,double y) 返回xy的值 double pow10(int p) 返回10p的值 double sqrt(double x) 返回+√x的值 double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度 double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度 double atan(double x) 返回x的反正切tan-1(x)值,x为弧度 double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度double cos(double x) 返回x的余弦cos(x)值,x为弧度 double sin(double x) 返回x的正弦sin(x)值,x为弧度 double tan(double x) 返回x的正切tan(x)值,x为弧度 double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度 double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度

C语言中常用的库函数

字符处理函数 本类别函数用于对单个字符进行处理,包括字符的类别测试和字符的大小写转换 头文件ctype.h 函数列表<> 函数类别函数用途详细说明 字符测试是否字母和数字isalnum 是否字母isalpha 是否控制字符iscntrl 是否数字isdigit 是否可显示字符(除空格外)isgraph 是否可显示字符(包括空格)isprint 是否既不是空格,又不是字母和数字的可显示字符ispunct 是否空格isspace 是否大写字母isupper 是否16进制数字(0-9,A-F)字符isxdigit 字符大小写转换函数转换为大写字母toupper 转换为小写字母tolower 地区化 本类别的函数用于处理不同国家的语言差异。 头文件local.h 函数列表 函数类别函数用途详细说明 地区控制地区设置setlocale 数字格式约定查询国家的货币、日期、时间等的格式转换localeconv 数学函数 本分类给出了各种数学计算函数,必须提醒的是ANSI C标准中的数据格式并不符合IEEE754标准,一些C语言编译器却遵循IEEE754(例如frinklin C51) 头文件math.h 函数列表 函数类别函数用途详细说明 错误条件处理定义域错误(函数的输入参数值不在规定的范围内) 值域错误(函数的返回值不在规定的范围内) 三角函数反余弦acos 反正弦asin

反正切atan 反正切2 atan2 余弦cos 正弦sin 正切tan 双曲函数双曲余弦cosh 双曲正弦sinh 双曲正切tanh 指数和对数指数函数exp 指数分解函数frexp 乘积指数函数fdexp 自然对数log 以10为底的对数log10 浮点数分解函数modf 幂函数幂函数pow 平方根函数sqrt 整数截断,绝对值和求余数函数求下限接近整数ceil 绝对值fabs 求上限接近整数floor 求余数fmod 本分类函数用于实现在不同底函数之间直接跳转代码。头文件setjmp.h io.h 函数列表 函数类别函数用途详细说明 保存调用环境setjmp 恢复调用环境longjmp 信号处理 该分类函数用于处理那些在程序执行过程中发生例外的情况。 头文件signal.h 函数列表 函数类别函数用途详细说明 指定信号处理函数signal 发送信号raise 可变参数处理 本类函数用于实现诸如printf,scanf等参数数量可变底函数。

C语言常用函数名及用法

字符函数和字符串函数 头文件:字符串函数头文件:#include 字符函数头文件:#include putchar:输出一个 putchar(a):输出字符变量a的值,(其中a可为字符变量,整形变量,字符常量,整形常量) getchar:输入一个字符 a=getchar(); putchar(a);结果为b printf(格式控制符,输出列表); scanf(格式控制符,地址列表); 输入形式与格式控制部分对应 1.当为两个连续输入时:scanf(“%d%d”,&a,&b); 输入量数据之间可为:一个或多个空格,也可以用enter,tab无逗号时输入时不能用逗号作分隔。 2.格式控制中两%d有两个空格,输入时两数据间应有两个空格或两个以上。 3.当为“:”时输入时应对应一样,当为:scanf(“a=%d,b=%d”,&a,&b);输入a=12,b=22。 4.当格式控制符为%c时,输入时空格与转义字符都作为有效字符记录在里面:scanf(“%c%c%c”,&a,&b,&c); 输入时:ab c↙空间不能插空格或其他符

5. Scanf(“%d%c%f”,&a,&b,&c); 输入时1234a123h26↙在输入遇到时空格回车 tab或其他非法输入就会认定输入完毕 Gets (字符数组):读入字符串函数 Gets(str)从键盘键入a b↙括号里为字符数组str的起始地址,Puts(字符数组):输出字符串函数 Strcat(字符数组1,字符数组2):字符串连接函数(2连接在1后面) Strcpy和strncpy:字符串复制函数 Strcpy(字符数组1,字符数组2):将2复制到1 数组1 要为数组名,字符串2可以为数组名或者字符串 Strncpy(str1,str2,2):将str2的前两个字符复制到str1,取代str1的前两个字符 Strcmp:字符串比较函数 Strcmp(str1,str2):相等则为0(对字符串自左向右逐个字母进行比较) Strlen(字符数组):测字符串的实际长度 Strlwr(字符串)将字符串转换为大写 Strupr(字符串)将字符串转换为小写

C语言常用的库函数

库函数并不是C语言的一部分,它是由编译系统根据一般用户的需要编制并 提供给用户使用的一组程序。每一种C编译系统都提供了一批库函数,不同的 编译系统所提供的库函数的数目和函数名以及函数功能是不完全相同的。ANSI C标准提出了一批建议提供的标准库函数。它包括了目前多数C编译系统所提供 的库函数,但也有一些是某些C编译系统未曾实现的。考虑到通用性,本附录 列出ANSI C建议的常用库函数。 由于C库函数的种类和数目很多,例如还有屏幕和图形函数、时间日期函数、 与系统有关的函数等,每一类函数又包括各种功能的函数,限于篇幅,本附录不 能全部介绍,只从教学需要的角度列出最基本的。读者在编写C程序时可根据 需要,查阅有关系统的函数使用手册。 1.数学函数 使用数学函数时,应该在源文件中使用预编译命令: #include或#include "math.h" 函数名函数原型功能返回值 acos double acos(double x);计算arccos x的值,其中-1<=x<=1计算结果 asin double asin(double x);计算arcsin x的值,其中-1<=x<=1计算结果 atan double atan(double x);计算arctan x的值计算结果 atan2double atan2(double x, double y);计算arctan x/y的值计算结果 cos double cos(double x);计算cos x的值,其中x的单位为弧度计算结果 cosh double cosh(double x);计算x的双曲余弦cosh x的值计算结果 exp double exp(double x);求e x的值计算结果

C语言函数大全

功能: 异常终止一个进程 用法: void abort(void) 函数名: abs 功能: 求整数的绝对值 用法: int abs(int i) 函数名: absread, abswirte 功能: 绝对磁盘扇区读、写数据 用法: int absread(int drive, int nsects, int sectno, void *buffer) int abswrite(int drive, int nsects, in tsectno, void *buffer 函数名: access 功能: 确定文件的访问权限 用法: int access(const char *filename, int amode) 函数名: acos 功能:反余弦函数 用法: double acos(double x) 函数名: allocmem 功能: 分配DOS存储段 用法:int allocmem(unsigned size, unsigned *seg) 函数名: arc 功能: 画一弧线 用法:void far arc(int x, int y, int stangle, int endangle, int radius)函数名: asctime 功能: 转换日期和时间为ASCII码 用法:char *asctime(const struct tm *tblock) 函数名: asin 功能:反正弦函数 用法: double asin(double x) 函数名: assert 功能: 测试一个条件并可能使程序终止 用法:void assert(int test) 函数名: atan 功能: 反正切函数 用法: double atan(double x)

c语言中常用的函数和头文件

头文件ctype.h 函数列表<> 函数类别函数用途详细说明 字符测试是否字母和数字isalnum 是否字母isalpha 是否控制字符iscntrl 是否数字isdigit 是否可显示字符(除空格外)isgraph 是否可显示字符(包括空格)isprint 是否既不是空格,又不是字母和数字的可显示字符ispunct 是否空格isspace 是否大写字母isupper 是否16进制数字(0-9,A-F)字符isxdigit 字符大小写转换函数转换为大写字母toupper 转换为小写字母tolower 地区化 本类别的函数用于处理不同国家的语言差异。 头文件local.h 函数列表 函数类别函数用途详细说明 地区控制地区设置setlocale 数字格式约定查询国家的货币、日期、时间等的格式转换localeconv 数学函数 本分类给出了各种数学计算函数,必须提醒的是ANSI C标准中的数据格式并不符合IEEE754标准,一些C语言编译器却遵循IEEE754(例如frinklin C51) 头文件math.h 函数列表 函数类别函数用途详细说明 错误条件处理定义域错误(函数的输入参数值不在规定的范围内) 值域错误(函数的返回值不在规定的范围内) 三角函数反余弦acos 反正弦asin 反正切atan 反正切2 atan2 余弦cos

正弦sin 正切tan 双曲函数双曲余弦cosh 双曲正弦sinh 双曲正切tanh 指数和对数指数函数exp 指数分解函数frexp 乘积指数函数fdexp 自然对数log 以10为底的对数log10 浮点数分解函数modf 幂函数幂函数pow 平方根函数sqrt 整数截断,绝对值和求余数函数求下限接近整数ceil 绝对值fabs 求上限接近整数floor 求余数fmod 本分类函数用于实现在不同底函数之间直接跳转代码。头文件setjmp.h io.h 函数列表 函数类别函数用途详细说明 保存调用环境setjmp 恢复调用环境longjmp 信号处理 该分类函数用于处理那些在程序执行过程中发生例外的情况。 头文件signal.h 函数列表 函数类别函数用途详细说明 指定信号处理函数signal 发送信号raise 可变参数处理 本类函数用于实现诸如printf,scanf等参数数量可变底函数。 头文件stdarg.h 函数列表

【C语言吧】做游戏常用函数

时间延迟函数 函数名: delay 功能: 将程序的执行暂停一段时间(毫秒) 用法: void delay(unsigned milliseconds); 重画屏幕区域的函数 函数名:getimage 功能:将指定区域的一个位图存到主存中 用法:void far getimage( int left, int top, int right, int bottom, void far *bitmap); 函数名:putimage 功能:在屏幕上输出一个位图 用法:void far putimage( int x, int y, void far *bitmap, int op ); 图像大小函数 函数名: imagesize 功能: 返回保存位图像所需的字节数 用法: unsigned far imagesize( int left, int top, int right, int bottom ); 异或模式函数 函数名: setwritemode 功能: 设置图形方式下画线的输出模式 用法: void far setwritemode(int mode); 参数MODE可以被设置位COPY_PUT或者XOR_PUT两种模式。当mode被设置为XOR_PUT,其后的图形操作将都采用异或方式。此外之前提到的putimage()函数也可以采用异或模式向屏幕复制图像。 检测键盘输入函数 函数名: kbhit 功能: 检查当前按下的键 用法: int kbhit(void); 键盘接口函数 函数名: bioskey 功能: 直接使用BIOS服务的键盘接口 用法: int bioskey(int cmd); 该函数通过bois中断0x16执行键盘操作,由参数cmd来决定具体的操作。 Cmd 具体操作 0 读取按键的ascii码 1 测试是否有按键如果没有按键返回0 如果按键为ctrl+brk 返回-1 如果是其他按键返回按键本身键值(直到此按键被取出后恢复0) 2 返回shift key 状态 以下是当cmd为2的时候,返回值的具体含义

C语言中游戏编程常用的函数实例解说

VGA文本16/256K40*25360*4009*16B8000彩色 CGA文本16/1680*25640*2008*8B8000彩色 2/3EGA文本16/6480*25640*3508*14B8000彩色 VGA(3+)文本16/256K80*25720*4009*16B8000彩色 CGA图形4/1640*25320*2008*8B8000彩色 4/5EGA图形4/6440*25320*2008*8B8000彩色 VGA图形4/256K40*25320*2008*8B8000彩色 CGA图形2/1640*25640*2008*8B8000单色 6EGA图形2/6440*25640*2008*8B8000单色 VGA图形2/256K40*25640*2008*8B8000单色 7MDA/EGA文本单色80*25720*3509*14B0000单色 VGA(7+)文本单色80*25720*4009*16B0000单色 D EGA图形16/6440*25320*2008*8A0000彩色 VGA图形16/256K40*25320*2008*8A0000彩色 E EGA图形16/6480*25640*2008*8A0000彩色 VGA图形16/256K80*25640*2008*8A0000彩色 F EGA/VGA图形单色80*25640*3508*14A0000单色 10EGA图形16/6480*25640*3508*14A0000彩色 VGA图形16/256K80*25640*3508*14A0000彩色 11VGA图形2/256K80*30640*4808*16A0000彩色 12VGA图形16/256K80*30640*4808*16A0000彩色 13VGA图形256/256K40*25320*2008*8A000彩色 常规内存函数 申请函数: malloc(),farmalloc(),calloc(),farcalloc(),realloc(),farealloc()函数名:malloc 功能:内存分配函数 用法:void*malloc(unsigned size); 函数名:farmalloc 功能:从远堆中分配存储块 用法:void far*farmalloc(unsigned long size); 函数名:calloc 功能:分配主存储器 用法:void*calloc(size_t nelem,size_t elsize); 函数名:farcalloc 功能:从远堆栈中申请空间

C语言中常见的功能函数

C语言中常见的功能函数(应掌握的编程) 1、两个变量值的交换 void exchang(float *x,float *y) /*形参为两个变量的地铁(指针)*/ {float z; z=*x; *x=*y; *y=z; } void main() {float a,b; scanf(“%f%f”,&a,&b); exchang(&a,&b); /*因为形参是指针,所以实参必须给变量的地址,不能给变量名*/ printf(“a=%f,b=%f”,a,b); } 2、判断一个整数的奇偶 int jou(int n) /*如果是奇数返回1,否则返回0*/ { if(n%2==0) return 0; return 1; } 3、小写字符转换成大写字符 根据实参传给形参的字母,判断是否是小写字母,如果是小写字母,则转换成大写字母,否则不进行转换,函数返回转换后或原来的字符。 本函数仿照toupper()库函数的功能编写(toupper(c) 是将变量c字母转换成大写字母,如果不是小写字母不转换)。 char toupper1(char ch) {if(ch>=’a’&&ch<=’z’) ch-=32; /*小写字母比对应的大写字母ASCII码值大32*/ return ch; } 4、判断一个字符是否是字母(或数字) 根据实参传给形参的字符,判断是否是字母(或数字),如果是字母(或数字)返回1,否则返回0。此函数是根据库函数isalpha()(或isdigit())来编写的。 int isalpha1(char ch) /*判断是否是字母*/ {if(ch>=’A’&&ch<=’Z’||ch>=’a’&&ch<=’z’) return 1; else return 0; } int isdigit1(char ch) /*判断是否是数字字符*/ {if(ch>=’0’&&ch<=’9’) return 1; else return 0; } 5、根据学生成绩,返回其等级 char fun(float cj) {char c; switch((int)cj/10) {case 10:

C语言常用函数

函数名: abort 功能: 异常终止一个进程 用法: void abort(void); 程序例: #include #include int main(void) { printf("Calling abort()\n"); abort(); return 0; /* This is never reached */ } 函数名: abs 功能: 求整数的绝对值 用法: int abs(int i); 程序例: #include #include int main(void) { int number = -1234; printf("number: %d absolute value: %d\n", number, abs(number)); return 0; } 函数名: absread, abswirte 功能: 绝对磁盘扇区读、写数据 用法: int absread(int drive, int nsects, int sectno, void *buffer); int abswrite(int drive, int nsects, in tsectno, void *buffer); 程序例: /* absread example */ #include #include #include #include int main(void) { int i, strt, ch_out, sector; char buf[512]; printf("Insert a diskette into drive A and press any key\n"); getch(); sector = 0; if (absread(0, 1, sector, &buf) != 0) {

常用C语言标准库函数

常用C语言标准库函数 C语言编译系统提供了众多的预定义库函数和宏。用户在编写程序时,可以直接调用这些库函数和宏。这里选择了初学者常用的一些库函数,简单介绍了各函数的用法和所在的头文件。 1.测试函数 Isalnum 原型:int isalnum(int c) 功能:测试参数c是否为字母或数字:是则返回非零;否则返回零 头文件:ctype.h Isapha 原型:int isapha(int c) 功能:测试参数c是否为字母:是则返回非零;否则返回零 头文件:ctype.h Isascii 原型:int isascii(int c) 功能:测试参数c是否为ASCII码(0x00~0x7F):是则返回非零;否则返回零 头文件:ctype.h Iscntrl 原型:int iscntrl(int c) 功能:测试参数c是否为控制字符(0x00~0x1F、0x7F):是则返回非零;否则返回零头文件:ctype.h Isdigit 原型:int isdigit(int c) 功能:测试参数c是否为数字:是则返回非零;否则返回零。 头文件:ctype.h Isgraph 原型:int isgraph(int c) 功能:测试参数c是否为可打印字符(0x21~0x7E):是则返回非零;否则返回零 头文件:ctype.h Islower 原型:int islower(int c) 功能:测试参数c是否为小写字母:是则返回非零;否则返回零 头文件:ctype.h Isprint 原型:int isprint(int c) 功能:测试参数c是否为可打印字符(含空格符0x20~0x7E):是则返回非零;否则返回零 头文件:ctype.h Ispunct 原型:int ispunct(int c) 功能:测试参数c是否为标点符号:是则返回非零;否则返回零

C语言常用头文件及函数

#include(errno.h):错误处理 #include (stdio.h):格式化输入与输出函数 fprintf函数,功能:格式输出(文件) fscanf函数,功能:格式输入(文件) printf函数,功能:格式输出(控制台) scanf函数,功能:格式输入(控制台) fclose函数,功能:关闭文件 fopen函数,功能:打开文件 feof函数,功能:文件结尾判断 ferror函数,功能:文件错误检测 freopen函数,功能:将已存在的流指针和新文件连接 setbuf函数,功能:设置磁盘缓冲区 sscanf函数,功能:从缓冲区中按格式输入 sprintf函数,功能:格式输出到缓冲区 remove函数,功能:删除文件 rename函数,功能:修改文件名称 tmpfile函数,功能:生成临时文件名称 tmpnam函数,功能:得到临时文件路径 fgetc函数,功能:输入一个字符(文件) fgets函数,功能:字符串输入(文件) fputc函数,功能:字符输出(文件) fputs函数,功能:字符串输出(文件) gets函数,功能:字符串输入(控制台) getchar函数,功能:字符输入(控制台) getc函数,功能:字符输入(控制台) putc函数,功能:字符输出(控制台) putchar函数,功能:字符输出(控制台) ungetc函数,功能:字符输出到流的头部 fread函数,功能:直接流读操作 fwrite函数,功能:直接流写操作 fgetpos函数,功能:得到文件位置 fsetpos函数,功能:文件位置设置 fseek函数,功能:文件位置移动 ftell函数,功能:得到文件位置 remind函数,功能:文件位置复零位 perror函数,功能:得到错误提示字符串 clearerr函数,功能:错误清除 puts函数,功能:字符串输出(控制台)

C语言中常用函数大全

(一)输入输出常用函数 1,printf (1)有符号int %[-][+][0][width][.precision][l][h] d -:左对齐 +:正数前加‘+’ 0:右对齐,acwidth.precision,按实际输出,否者左边补零 (2)无符号int %[-][#][0][width][.precision][l][h] u|o|x|X #:”%o %x/X”输出0,0x,0X .precision:同上,TC/BC包含0x/X,VC下不包含 (3)实数输出 %[-][+][#][0][width][.precision][l][L] f|e|E|g|G #:必须输出小数点 .precision:小数位数(四舍五入) (4)字符和字符串的输出 %[-][0][width] c %[-][0][width] [.precision] s .precision:S的前precision位 2,scanf %[*][width] [l][h]Type With:指定输入数据的宽度,遇空格、Tab、\n结束 *:抑制符scanf(“%2d%*2d%3d”,&num1,&num2) 输入123456789\n;num1==12,num2==567. 注意: (1)指定width时,读取相应width位,但按需赋值 Scanf(“%3c%3c”,&ch1,&ch2)输入a bc d efg ch1==a ch2==d (2)%c 输入单字符时“空格、转义字符”均是有效字符 (二)ascll字符/字符串/文件函数 1;字符非格式化输入函数 (1)int getchar(void) 接受字符,以回车结束,回显 (2)int getc(FILE*stream) 从stream中接受字符,以回车结束,回显stream=stdin时,(1)==(2)(3)int getche(void) 直接读取字符,回显conio.h

(整理)C语言常用算法集合.

1.定积分近似计算: /*梯形法*/ double integral(double a,double b,long n) { long i;double s,h,x; h=(b-a)/n; s=h*(f(a)+f(b))/2; x=a; for(i=1;i

} 3.素数的判断: /*方法一*/ for (t=1,i=2;i0;n/=10) k=10*k+n%10; return k; } /*求回文数*/ int f(long n) { long k,m=n; for(k=0;n>0;n/=10) k=10*k+n%10; if(m==k) return 1; return 0; } /*求整数位数*/ int f(long n) { int count; for(count=0;n>0;n/=10) count++; return count; }

单片机C语言(C51)的常用库函数

C51的常用库函数详解 C51语言的编译器中包含有丰富的库函数,使用库函数可以大大简化用户程序设计的工作量,提高编程效率。每个库函数都在相应的头文件中给出了函数原型声明,在使用时,必须在源程序的开始处使用预处理命令#include将有关的头文件包含进来。 C51库函数中类型的选择考虑到了8051单片机的结构特性,用户在自己的应用程序中应尽可能地使用最小的数据类型,以最大限度地发挥8051单片机的性能,同时可减少应用程序的代码长度。下面将C51的库函数分类列出并详细介绍其用法。 1 字符函数 字符函数的原型声明包含在头文件CTYPE.H中。常用的一些字符函数介绍如下。1.1 检查英文字母函数 检查英文字母函数用于检查形参字符是否为英文字母,其函数原型如下: bit isalpha(char c); 其中,c为待判断的字符,如果是英文字母则返回1,否则返回0。程序示例如下: 1.2 检查字母数字函数 检查字母数字函数用于检查形参字符是否为英文字母或数字字符,其函数原型如下:bit isalnum(char c);

1.3 检查控制字符函数 检查控制字符函数用于检查形参字符是否为控制字符,其函数原型:bit iscntrl (char c);其中,c为待判断的字符。控制字符其取值范围为0x00~0xlF之间或等于0x7F,如果 是,则返回1,否则返回0。

1.4 十进制数字检查函数 十进制数字检查函数用于检查形参字符是否为十进制数字,其函数原型如下: bit isdigit (char c); 其中,c为待判断的字符,如果是十进制数字则返回1,否则返回0。 1.5 可打印字符检查函数 可打印字符检查函数用于检查形参字符是否为可打印字符,其函数原型如下: bit isgraph (char c); 其中,c为待判断的字符。可打印字符的取值范围为0x21~0x7C,不包含空格,如果是可打印字符则返回1,否则返回0。

c语言中常用函数大全

如对您有帮助,请购买打赏,谢谢您! (一)输入输出常用函数 1,printf (1)有符号int %[-][+][0][width][.precision][l][h] d -:左对齐 +:正数前加‘+’ 0:右对齐,acwidth.precision,按实际输出,否者左边补零 (2)无符号int %[-][#][0][width][.precision][l][h] u|o|x|X #:”%o %x/X”输出0,0x,0X .precision:同上,TC/BC包含0x/X,VC下不包含 (3)实数输出 %[-][+][#][0][width][.precision][l][L] f|e|E|g|G #:必须输出小数点 .precision:小数位数(四舍五入) (4)字符和字符串的输出 %[-][0][width] c %[-][0][width] [.precision] s .precision:S的前precision位 2,scanf %[*][width] [l][h]Type With:指定输入数据的宽度,遇空格、Tab、\n结束 *:抑制符scanf(“%2d%*2d%3d”,&num1,&num2) 输入9\n;num1==12,num2==567. 注意: (1)指定width时,读取相应width位,但按需赋值 Scanf(“%3c%3c”,&ch1,&ch2)输入a bc d efg ch1==a ch2==d (2)%c 输入单字符时“空格、转义字符”均是有效字符 (二)ascll字符/字符串/文件函数 1;字符非格式化输入函数 (1)int getchar(void) 接受字符,以回车结束,回显 (2)int getc(FILE*stream) 从stream中接受字符,以回车结束,回显stream=stdin时,(1)==(2) (3)int getche(void) 直接读取字符,回显conio.h (4)int getchar(void) 直接读取字符,不回显conio.h

C语言常用数学函数及其用法

三角函数:(所有参数必须为弧度) 1.acos 函数申明:acos (double x); 用途:用来返回给定的X 的反余弦 函数。 2.asin 函数申明:asin (double x); 用途:用来返回给定的X 的反正弦 函数。 3.atan 函数申明:atan (double x); 用途:用来返回给定的X 的反正切 函数。 4.sin 函数声明:sin (double x); 用途:用来返回给定的X 的正弦值。 5.cos 函数声明:cos (double x); 用途:用来返回给定的X 的余弦值。 6.tan 函数声明:tan (double x); 用途:用来返回给定的X 的正切值。 7.atan2 函数声明:atan2 (double y, double x); 用途:返回给定的X 及Y 坐标值的反正切值其他函数: 8.atof 函数名: atof (const char *s); 功能: 把字符串转换成浮点数 用法: double atof(const char *nptr); 程序例: #i nclude #i nclude int main(void) { float arg,*point=&arg; float f; char *str = "12345.67"; f = atof(str); printf("string = %s float = %f\n", str, f); return 0; } 9. ceil 和 floor 函数名: ceil floor 功能: 向上舍入 向下舍入 用法: double ceil(double x); double floor(double x); 程序例: #i nclude int main(void) { double number = 123.54; double down, up;

C语言常用函数及用法

C语言常用数学函数及其用法三角函数:(所有参数必须为弧度) 1.acos 函数申明:acos (double x); 用途:用来返回给定的X 的反余弦函数。 2.asin 函数申明:asin (double x); 用途:用来返回给定的X 的反正弦函数。 3.atan 函数申明:atan (double x); 用途:用来返回给定的X 的反正切函数。 4.sin 函数声明:sin (double x); 用途:用来返回给定的X 的正弦值。 5.cos 函数声明:cos (double x); 用途:用来返回给定的X 的余弦值。 6.tan 函数声明:tan (double x); 用途:用来返回给定的X 的正切值。 7.atan2 函数声明:atan2 (double y, double x); 用途:返回给定的X 及Y 坐标值的反正切值 其他函数:

8.atof 函数名: atof (const char *s); 功能: 把字符串转换成浮点数 用法: double atof(const char *nptr); 程序例: #i nclude #i nclude int main(void) { float arg,*point=&arg; float f; char *str = "12345.67"; f = atof(str); printf("string = %s float = %f\n", str, f); return 0; } 9. ceil 和floor 函数名: ceil floor 功能: 向上舍入 向下舍入 用法: double ceil(double x); double floor(double x); 程序例: #i nclude int main(void) { double number = 123.54; double down, up; down = floor(number); up = ceil(number); printf("original number %5.2lf\n", number); printf("number rounded down %5.2lf\n", down); printf("number rounded up %5.2lf\n", up); return 0; }该程序运行结果:original number 123.54 number rounded down 123.00

相关主题
相关文档 最新文档