c语言 copy子函数,C语言标准库函数(网络上copy的)

本文详细介绍了C语言的标准库函数,包括IO函数如fopen/fclose/fread/fwrite等,字符/字符串处理函数如strlen/strcpy/strcat等,数学函数如sqrt/pow/log等,以及时间/日期函数和内存管理函数。这些函数构成了C语言编程的基础工具集合。
摘要由CSDN通过智能技术生成

C语言标准库函数

85ce724cdccc1d2177a5be84f500f827.png

标准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

原文:http://www.cnblogs.com/sanchrist/p/3574043.html

### C语言标准库函数概述 C语言提供了丰富的标准库函数来简化编程工作。这些函数被分类到不同的头文件中,开发者可以根据需求引入相应的头文件并调用其中定义的功能[^1]。 #### 字符串处理函数 字符串操作是程序设计中的常见任务之一,在`<string.h>`这个头文件里声明了一系列用于管理和修改字符数组(即所谓的“字符串”)的工具函数。例如: - `strlen()`计算给定字符串的实际长度而不计入终止符`\0`; - `strcpy()`实现两个字符串之间的复制动作;而 - `strcat()`负责连接两段文本序列形成新的整体[^2]。 ```c #include <stdio.h> #include <string.h> int main() { char src[] = "hello"; char dest[50]; strcpy(dest, src); // 复制src至dest printf("Copy result:%s\n", dest); } ``` #### 数学运算支持 对于涉及数值分析的应用场景来说,`math.h`提供了一些基本算术运算之外更高级别的数学服务,像求平方根(`sqrt`)、绝对值(`fabs`)以及三角函数等都封装在此处等待调用者使用[^3]。 ```c #include <stdio.h> #include <math.h> int main(){ double num=9.0; printf("Square root of %.lf is %.lf\n",num,sqrt(num)); } ``` #### 输入输出管理 输入/输出流控制也是不可或缺的一部分功能集合。<stdio.h>不仅包含了格式化读写终端数据的方法如`printf()/scanf()`,还扩展到了文件系统的访问层面——通过`fopen(), fread(), fwrite(), fclose()`等一系列接口完成对外部资源的操作过程[^4]。 ```c #include <stdio.h> int main () { FILE *fp; fp = fopen ("example.txt","w+"); fprintf(fp,"This is an example."); rewind (fp); char str[100]; fgets(str,sizeof(str),fp); puts(str); fclose(fp); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值