C語言庫函數,常用庫函數有:
成都創(chuàng)新互聯于2013年創(chuàng)立,先為石獅等服務建站,石獅等地企業(yè),進行企業(yè)商務咨詢服務。為石獅企業(yè)網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。
1、scanf格式輸入函數
2、printf格式輸出函數
3、systemdos命令函數
4、sort排序
5、main主函數
6、fgets文件讀取字符串函數
7、fputs文件寫入字符串函數
8、fscanf文件格式讀取函數
9、fprintf文件格式寫入函數
10、fopen打開文件函數
11、getchar輸入字符函數
12、putchar輸出字符函數
13、malloc動態(tài)申請內存函數
14、free釋放內存函數
15、abs求絕對值數學函數
16、sqrt求平方根數學函數
擴展資料
語言組成:
1、數據類型
C的數據類型包括:整型、字符型、實型或浮點型(單精度和雙精度)、枚舉類型、數組類型、結構體類型、共用體類型、指針類型和空類型。
2、常量與變量
常量其值不可改變,符號常量名通常用大寫。
變量是以某標識符為名字,其值可以改變的量。標識符是以字母或下劃線開頭的一串由字母、數字或下劃線構成的序列,請注意第一個字符必須為字母或下劃線,否則為不合法的變量名。變量在編譯時為其分配相應存儲單元。
3、數組
如果一個變量名后面跟著一個有數字的中括號,這個聲明就是數組聲明。字符串也是一種數組。它們以ASCII的NULL作為數組的結束。要特別注意的是,方括內的索引值是從0算起的。
4、指針
如果一個變量聲明時在前面使用 * 號,表明這是個指針型變量。換句話說,該變量存儲一個地址,而 *(此處特指單目運算符 * ,下同。C語言中另有 雙目運算符 *) 則是取內容操作符,意思是取這個內存地址里存儲的內容。指針是 C 語言區(qū)別于其他同時代高級語言的主要特征之一。
參考資料來源:百度百科-函數
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
1)字符串操作
strcpy(p, p1) 復制字符串
strncpy(p, p1, n) 復制指定長度字符串
strcat(p, p1) 附加字符串
strncat(p, p1, n) 附加指定長度字符串
strlen(p) 取字符串長度
strcmp(p, p1) 比較字符串
strcasecmp忽略大小寫比較字符串
strncmp(p, p1, n) 比較指定長度字符串
strchr(p, c) 在字符串中查找指定字符
strrchr(p, c) 在字符串中反向查找
strstr(p, p1) 查找字符串
strpbrk(p, p1) 以目標字符串的所有字符作為集合,在當前字符串查找該集合的任一元素
strspn(p, p1) 以目標字符串的所有字符作為集合,在當前字符串查找不屬于該集合的任一元素的偏移
strcspn(p, p1) 以目標字符串的所有字符作為集合,在當前字符串查找屬于該集合的任一元素的偏移
* 具有指定長度的字符串處理函數在已處理的字符串之后填補零結尾符
2)字符串到數值類型的轉換
strtod(p, ppend) 從字符串 p 中轉換 double 類型數值,并將后續(xù)的字符串指針存儲到 ppend 指向的 char* 類型存儲。
strtol(p, ppend, base) 從字符串 p 中轉換 long 類型整型數值,base 顯式設置轉換的整型進制,設置為 0 以根據特定格式判斷所用進制,0x, 0X 前綴以解釋為十六進制格式整型,0 前綴以解釋為八進制格式整型
atoi(p) 字符串轉換到 int 整型
atof(p) 字符串轉換到 double 符點數
atol(p) 字符串轉換到 long 整型
3)字符檢查
isalpha() 檢查是否為字母字符
isupper() 檢查是否為大寫字母字符
islower() 檢查是否為小寫字母字符
isdigit() 檢查是否為數字
isxdigit() 檢查是否為十六進制數字表示的有效字符
isspace() 檢查是否為空格類型字符
iscntrl() 檢查是否為控制字符
ispunct() 檢查是否為標點符號
isalnum() 檢查是否為字母和數字
isprint() 檢查是否是可打印字符
isgraph() 檢查是否是圖形字符,等效于 isalnum() | ispunct()
其實在C語言編程中,我們所用的在部分函數就是C語言庫本身帶的函數,在使用某一個庫文件之前,我們先要包含庫文件所對應的頭文件,再在我們需要的地方調用庫函數就行了.最常用的printf();這就是一個庫函數,這個庫函數在頭文件stdio.h中聲明.所以使用前要先#include stdio.h
舉個例子:
#include stdio.h //一定要先包含庫函數聲明的文件
int main()
{
printf("for example!\n"); //在此處調用庫函數
}
如果想要了解更多的庫函數,可以參考C語言的教材,一般的附錄中會列出.也可以查看C庫函數.