资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言标准数学函数库 c++标准函数库

在C中,什么是标准库函数?

在 C语言程序设计里,C 标准函数库(C Standard library)  是所有符合标准的头文件(head file)的集合,以及常用的函数库实现程序,例如I/O 输入输出和字符串控制。不像 COBOL、Fortran 和 PL/I等编程语言,在 C 语言的工作任务里不会包含嵌入的关键字,所以几乎所有的 C 语言程序都是由标准函数库的函数来创建的。

成都网站设计、成都网站建设的关注点不是能为您做些什么网站,而是怎么做网站,有没有做好网站,给成都创新互联一个展示的机会来证明自己,这并不会花费您太多时间,或许会给您带来新的灵感和惊喜。面向用户友好,注重用户体验,一切以用户为中心。

每一个函数的名称与特性会被写成一个电脑文件,这个文件就称为头文件,但是实际的函数实现是被分存到函数库文件里。头文件的命名和领域是很常见的,但是函数库的组织架构也会因为不同的编译器而有所不同。标准函数库通常会随附在编译器上。因为 C 编译器常会提供一些额外的非 ANSI C 函数功能,所以某个随附在特定编译器上的标准函数库,对其他不同的编译器来说,是不兼容的。

C语言基础-数学函数库

一些数学计算的公式的具体实现是放在math.h里,具体有:

x的正弦值

double sin (double x);

x的余弦值

double cos (double x);

x的正切值

double tan (double x);

结果介于[-PI/2, PI/2],x值域为[-1,1]

double asin (double x);

结果介于[0, PI],x值域为[-1,1]

double acos (double x);

反正切(主值), 结果介于[-PI/2, PI/2]

double atan (double x);

反正切(整圆值), 结果介于[-PI, PI]

double atan2 (double y, double x);

x的双曲正弦值

double sinh (double x);

x的双曲余弦值

double cosh (double x);

x的双曲正切值

double tanh (double x);

幂函数e^x

double exp (double x);

x^y,如果x=0且y=0,或者x0且y不是整型数,将产生定义域错误

double pow (double x, double y);

x的平方根,其中x=0

double sqrt (double x);

以e为底的对数,自然对数,x0

double log (double x);

以10为底的对数,x0

double log10 (double x);

取上整

double ceil (double x);

取下整

double floor (double x);

x的绝对值

double fabs (double x);

标准化浮点数, x = f * 2^exp, 已知x求f, exp ( x介于[0.5, 1] )并返回f值

double frexp (double x, int *exp);

与frexp相反, 已知x, exp求x*2^exp

double ldexp (double x, int exp);

将参数的整数部分通过指针回传, 返回小数部分,整数部分保存在*ip中

double modf (double x, double *ip);

返回两参数相除x/y的余数,符号与x相同。如果y为0,则结果与具体的额实现有关

double fmod (double x, double y);

C语言中的标准函数有哪些?

C语言输入输出函数有很多,标准I/O函数中包含了如下几个常用的函数:

scanf,printf,getc,putc,getchar,putchar,gets,puts,fgets,fputs,fgetc,fputc,fscanf,fprintf等.

int

getc(FILE

*fp)

getc主要是从文件中读出一个字符.常用的判断文件是否读取结束的语句为

(ch

=

getc(fp))

!=

EOF.EOF为文件结束标志,定义在stdio.h中,就像EXIT_SUCCESS,EXIT_FAILURE定义在stdlib.h中一样,文件也可以被理解为一种流,所以当fp为stdin时,getc(stdin)就等同于getchar()了.

int

putc(int

ch,FILE

*fp)

putc主要是把字符ch写到文件fp中去.如果fp为stdout,则putc就等同于putchar()了.

int

getchar(void)

getchar主要是从标准输入流读取一个字符.默认的标准输入流即stdio.h中定义的stdin.但是从输入流中读取字符时又涉及到缓冲的问题,所以并不是在屏幕中敲上一个字符程序就会运行,一般是通过在屏幕上敲上回车键,然后将回车前的字符串放在缓冲区中,getchar就是在缓冲区中一个一个的读字符.当然也可以在while循环中指定终止字符,如下面的语句:while

((c

=

getchar())

!=

'#')这是以#来结束的.

int

putchar(int

ch)

putchar(ch)主要是把字符ch写到标准流stdout中去.

char

*

gets(char

*str)

gets主要是从标准输入流读取字符串并回显,读到换行符时退出,并会将换行符省去.

int

puts(char

*str)

puts主要是把字符串str写到标准流stdout中去,并会在输出到最后时添加一个换行符.

char

*fgets(char

*str,

int

num,

FILE

*fp)

str是存放读入的字符数组指针,num是最大允许的读入字符数,fp是文件指针.fgets的功能是读一行字符,该行的字符数不大于num-1.因为fgets函数会在末尾加上一个空字符以构成一个字符串.另外fgets在读取到换行符后不会将其省略.

int

fputs(char

*str,

file

*fp)

fputs将str写入fp.fputs与puts的不同之处是fputs在打印时并不添加换行符.

int

fgetc(FILE

*fp)

fgetc从fp的当前位置读取一个字符.

int

fputc(int

ch,

file

*fp)

fputc是将ch写入fp当前指定位置.

int

fscanf(FILE

*fp,

char

*format,

输入列表)

fscanf按照指定格式从文件中出读出数据,并赋值到参数列表中.

int

fprintf(FILE

*fp,

char

*format,

输出列表)

fprintf将格式化数据写入流式文件中.

数据块读写函数

fread

(buffer,size,count,fp);

fwrite(buffer,size,count,fp);

参数说明:

buffer:是一个指针。

对fread

来说,它是读入数据的存放地址。

对fwrite来说,是要输出数据的地址(均指起始地址)。

size:

要读写的字节数。

count:

要进行读写多少个size字节的数据项。

fp:

文件型指针。

C 语言标准库函数

C语言标准库函数

标准io函数

Standard C I/O

clearerr() clears errors

fclose() close a file

feof() true if at the end-of-file

ferror() checks for a file error

fflush() writes the contents of the output buffer

fgetc() get a character from a stream

fgetpos() get the file position indicator

fgets() get a string of characters from a stream

fopen() open a file

fprintf() print formatted output to a file

fputc() write a character to a file

fputs() write a string to a file

fread() read from a file

freopen() open an existing stream with a different name

fscanf() read formatted input from a file

fseek() move to a specific location in a file

fsetpos() move to a specific location in a file

ftell() returns the current file position indicator

fwrite() write to a file

getc() read a character from a file

getchar() read a character from STDIN

gets() read a string from STDIN

perror() displays a string version of the current error to STDERR

printf() write formatted output to STDOUT

putc() write a character to a stream

putchar() write a character to STDOUT

puts() write a string to STDOUT

remove() erase a file

rename() rename a file

rewind() move the file position indicator to the beginning of a file

scanf() read formatted input from STDIN

setbuf() set the buffer for a specific stream

setvbuf() set the buffer and size for a specific stream

sprintf() write formatted output to a buffer

sscanf() read formatted input from a buffer

tmpfile() return a pointer to a temporary file

tmpnam() return a unique filename

ungetc() puts a character back into a stream

vprintf, vfprintf, vsprintf write formatted output with variable argument lists

标准字符/字符串处理函数

atof() converts a string to a double

atoi() converts a string to an integer

atol() converts a string to a long

isalnum() true if alphanumeric

isalpha() true if alphabetic

iscntrl() true if control character

isdigit() true if digit

isgraph() true if a graphical character

islower() true if lowercase

isprint() true if a printing character

ispunct() true if punctuation

isspace() true if space

isupper() true if uppercase character

isxdigit() true if a hexidecimal character

memchr() searches an array for the first occurance of a character

memcmp() compares two buffers

memcpy() copies one buffer to another

memmove() moves one buffer to another

memset() fills a buffer with a character

strcat() concatenates two strings

strchr() finds the first occurance of a character in a string

strcmp() compares two strings

strcoll() compares two strings in accordance to the current locale

strcpy() copies one string to another

strcspn() searches one string for any characters in another

strerror() returns a text version of a given error code

strlen() returns the length of a given string

strncat() concatenates a certain amount of characters of two strings

strncmp() compares a certain amount of characters of two strings

strncpy() copies a certain amount of characters from one string to another

strpbrk() finds the first location of any character in one string, in another string

strrchr() finds the last occurance of a character in a string

strspn() returns the length of a substring of characters of a string

strstr() finds the first occurance of a substring of characters

strtod() converts a string to a double

strtok() finds the next token in a string

strtol() converts a string to a long

strtoul() converts a string to an unsigned long

strxfrm() converts a substring so that it can be used by string comparison functions

tolower() converts a character to lowercase

toupper() converts a character to uppercase

标准数学函数

abs() absolute value

acos() arc cosine

asin() arc sine

atan() arc tangent

atan2() arc tangent, using signs to determine quadrants

ceil() the smallest integer not less than a certain value

cos() cosine

cosh() hyperbolic cosine

div() returns the quotient and remainder of a division

exp() returns "e" raised to a given power

fabs() absolute value for floating-point numbers

floor() returns the largest integer not greater than a given value

fmod() returns the remainder of a division

frexp() decomposes a number into scientific notation

labs() absolute value for long integers

ldexp() computes a number in scientific notation

ldiv() returns the quotient and remainder of a division, in long integer form

log() natural logarithm

log10() natural logarithm, in base 10

modf() decomposes a number into integer and fractional parts

pow() returns a given number raised to another number

sin() sine

sinh() hyperbolic sine

sqrt() square root

tan() tangent

tanh() hyperbolic tangent

标准时间/日期函数

asctime() a textual version of the time

clock() returns the amount of time that the program has been running

ctime() returns a specifically formatted version of the time

difftime() the difference between two times

gmtime() returns a pointer to the current Greenwich Mean Time

localtime() returns a pointer to the current time

mktime() returns the calendar version of a given time

strftime() returns individual elements of the date and time

time() returns the current calendar time of the system

标准内存管理函数

calloc() allocates a two-dimensional chunk of memory

free() makes memory available for future allocation

malloc() allocates memory

realloc() changes the size of previously allocated memory

其它标准函数

abort() stops the program

assert() stops the program if an expression isn';t true

atexit() sets a function to be called when the program exits

bsearch() perform a binary search

exit() stop the program

getenv() get enviornment information about a variable

longjmp() start execution at a certain point in the program

qsort() perform a quicksort

raise() send a signal to the program

rand() returns a pseudorandom number

setjmp() set execution to start at a certain point

signal() register a function as a signal handler

srand() initialize the random number generator

system() perform a system call

va_arg() use variable length parameter lists

求教 C语言的数学库函数与标准库函数 有什么不同?

C语言的标准变化了好几次,现在说的标准C语言指的是99年制定的C99标准。其中定义的函数库就是C语言标准函数库。具体有哪些你可以查询《C语言参考手册(C:A Reference Manual,Fifth Edition》。

但事实上,每个C/C++编译器都带有自身的函数库,一般都兼容C标准函数库,但也有个别的有些细节上的出入。所以,一般你只要考察你所用编译器的函数库就行了(通常都可以从帮助中得到)。

数学函数是标准库函数的一种

c语言常用库函数有哪些

最低0.27元/天开通百度文库会员,可在文库查看完整内容

原发布者:shimingtime

附录CC语言常用的库函数库函数并不是C语言的一部分,它是由编译系统根据一般用户的需要编制并提供给用户使用的一组程序。每一种C编译系统都提供了一批库函数,不同的编译系统所提供的库函数的数目和函数名以及函数功能是不完全相同的。ANSIC标准提出了一批建议提供的标准库函数。它包括了目前多数C编译系统所提供的库函数,但也有一些是某些C编译系统未曾实现的。考虑到通用性,本附录列出ANSIC建议的常用库函数。由于C库函数的种类和数目很多,例如还有屏幕和图形函数、时间日期函数、与系统有关的函数等,每一类函数又包括各种功能的函数,限于篇幅,本附录不能全部介绍,只从教学需要的角度列出最基本的。读者在编写C程序时可根据需要,查阅有关系统的函数使用手册。1.数学函数使用数学函数时,应该在源文件中使用预编译命令:#include或#include"math.h"2.字符函数在使e68a84e8a2ade799bee5baa631333433623761用字符函数时,应该在源文件中使用预编译命令:#include或#include"ctype.h"3.字符串函数使用字符串中函数时,应该在源文件中使用预编译命令:#include或#include"string.h"4.输入输出函数在使用输入输出函数时,应该在源文件中使用预编译命令:#include或#include"stdio.h"5.动态存储分配函数在使用动态存储分配函数时,应该在源文件中使用预编译命令:#include或#include"stdlib.h"6.其他函数有些函数由于不便归入某一类,所以单独列出。使用这些


新闻名称:c语言标准数学函数库 c++标准函数库
当前URL:http://cdkjz.cn/article/docopsd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220