C语言标准库函数大全(ctype、time 、stdio、stdlib、math、string)
生活随笔
收集整理的這篇文章主要介紹了
C语言标准库函数大全(ctype、time 、stdio、stdlib、math、string)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- C語言函數庫:
- 一. <ctype.h>
- 二. <math.h>
- 三. <stdio.h>
- 四. <stdlib.h>
- 五. <time.h>
- 六. <string.h>
- 文檔資料
C語言函數庫:
C語言的常用的標準頭文件有 :
<ctype.h> ? <time.h> ? <stdio.h>
<stdlib.h> ? <math.h> ? <string.h>
一. <ctype.h>
| 1 | int iscntrl(int c) | 判斷字符c是否為控制字符。 |
| 2 | int isalnum(int c) | 判斷字符c是否為字母或數字 |
| 3 | int isalpha(int c) | 判斷字符c是否為英文字母 |
| 4 | int isascii(int c) | 判斷字符c是否為ascii碼 |
| 5 | int isblank(int c) | 判斷字符c是否為TAB或空格 |
| 6 | int isdigit(int c) | 判斷字符c是否為數字 |
| 7 | int isgraph(int c) | 判斷字符c是否為除空格外的可打印字符 |
| 8 | int islower(int c) | 判斷字符c是否為小寫英文字母 |
| 9 | int isprint(int c) | 判斷字符c是否為可打印字符(含空格) |
| 10 | int ispunct(int c) | 判斷字符c是否為標點符號 |
| 11 | int isspace(int c) | 判斷字符c是否為空白符 |
| 12 | int isupper(int c) | 判斷字符c是否為大寫英文字母 |
| 13 | int isxdigit(int c) | 判斷字符c是否為十六進制數字 |
| 14 | int toascii(int c) | 將字符c轉換為ascii碼 |
| 15 | int tolower(int c) | 將字符c轉換為小寫英文字母 |
| 16 | int toupper(int c); | 將字符c轉換為大寫英文字母 |
二. <math.h>
| 1 | float fabs(float x) | 求浮點數x的絕對值 |
| 2 | int abs(int x) | 求整數x的絕對值 |
| 3 | float acos(float x) | 求x(弧度表示)的反余弦值 |
| 4 | float asin(float x) | 求x(弧度表示)的反正弦值 |
| 5 | float atan(float x) | 求x(弧度表示)的反正切值 |
| 6 | float atan2(float y, float x) | 求y/x(弧度表示)的反正切值 |
| 7 | float ceil(float x) | 求不小于x的最小整數 |
| 8 | float cos(float x) | 求x(弧度表示)的余弦值 |
| 9 | float cosh(float x) | 求x的雙曲余弦值 |
| 10 | float exp(float x) | 求e的x次冪 |
| 11 | float floor(float x) | 求不大于x的最大整數 |
| 12 | float fmod(float x, float y) | 計算x/y的余數 |
| 13 | float frexp(float x, int *exp) | 把浮點數x分解成尾數和指數 |
| 14 | float ldexp(float x, int exp) | 返回x*2^exp的值 |
| 15 | float modf(float num, float *i) | 將浮點數num分解成整數部分和小數部分 |
| 16 | float hypot(float x, float y) | 對于給定的直角三角形的兩個直角邊,求其斜邊的長度 |
| 17 | float log(float x) | 計算x的自然對數 |
| 18 | float log10(float x) | 計算x的常用對數 |
| 19 | float pow(float x, float y) | 計算x的y次冪 |
| 20 | float pow10(float x) | 計算10的x次冪 |
| 21 | float sin(float x) | 計算x(弧度表示)的正弦值 |
| 22 | float sinh(float x) | 計算x(弧度表示)的雙曲正弦值 |
| 23 | float sqrt(float x) | 計算x的平方根 |
| 24 | float tan(float x); | 計算x(弧度表示)的正切值 |
| 25 | float tanh(float x) | 求x的雙曲正切值 |
三. <stdio.h>
| 1 | int printf(char *format...) | 產生格式化輸出的函數 |
| 2 | int getchar(void) | 從鍵盤上讀取一個鍵,并返回該鍵的鍵值 |
| 3 | int putchar(char c) | 在屏幕上顯示字符c |
| 4 | FILE *fopen(char *filename, char *type) | 打開一個文件 |
| 5 | FILE *freopen(char *filename, char *type,FILE *fp) | 打開一個文件,并將該文件關聯到fp指定的流 |
| 6 | int fflush(FILE *stream) | 清除一個流 |
| 7 | int fclose(FILE *stream) | 關閉一個文件 |
| 8 | int remove(char *filename) | 刪除一個文件 |
| 9 | int rename(char *oldname, char *newname) | 重命名文件 |
| 10 | FILE *tmpfile(void) | 以二進制方式打開暫存文件 |
| 11 | char *tmpnam(char *sptr) | 創建一個唯一的文件名 |
| 12 | int setvbuf(FILE *stream, char *buf, int type, unsigned size) | 把緩沖區與流相關 |
| 13 | int fprintf(FILE *stream, char *format[, argument,...]) | 傳送格式化輸出到一個流中 |
| 14 | int scanf(char *format[,argument,...]) | 執行格式化輸入 |
| 15 | int fscanf(FILE *stream, char *format[,argument...]) | 從一個流中執行格式化輸入 |
| 16 | int fgetc(FILE *stream) | 從流中讀取字符 |
| 17 | char *fgets(char *string, int n, FILE *stream) | 從流中讀取一字符串 |
| 18 | int fputc(int ch, FILE *stream) | 送一個字符到一個流中 |
| 19 | int fputs(char *string, FILE *stream) | 送一個字符到一個流中 |
| 20 | int getc(FILE *stream) | 從流中取字符 |
| 21 | int getchar(void) | 從 stdin 流中讀字符 |
| 22 | char *gets(char *string) | 從流中取一字符串 |
| 23 | int putchar(int ch) | 在 stdout 上輸出字符 |
| 24 | int puts(char *string) | 送一字符串到流中 |
| 25 | int ungetc(char c, FILE *stream) | 把一個字符退回到輸入流中 |
| 26 | int fread(void *ptr, int size, int nitems, FILE *stream) | 從一個流中讀數據 |
| 27 | int fwrite(void *ptr, int size, int nitems, FILE *stream) | 寫內容到流中 int fseek |
| 28 | (FILE *stream, long offset, int fromwhere) | 重定位流上的文件指針 |
| 29 | long ftell(FILE *stream) | 返回當前文件指針 |
| 30 | int rewind(FILE *stream) | 將文件指針重新指向一個流的開頭 |
| 31 | int fgetpos(FILE *stream) | 取得當前文件的句柄 |
| 32 | int fsetpos(FILE *stream, const fpos_t *pos) | 定位流上的文件指針 |
| 33 | void clearerr(FILE *stream) | 復位錯誤標志 |
| 34 | int feof(FILE *stream) | 檢測流上的文件結束符 |
| 35 | int ferror(FILE *stream) | 檢測流上的錯誤 |
| 36 | void perror(char *string) | 系統錯誤信息 |
四. <stdlib.h>
| 1 | char *itoa(int i) | 把整數i轉換成字符串 |
| 2 | void exit(int retval) | 結束程序 |
| 3 | double atof(const char *s) | 將字符串s轉換為double類型 |
| 4 | int atoi(const char *s) | 將字符串s轉換為int類型 |
| 5 | long atol(const char *s) | 將字符串s轉換為long類型 |
| 6 | double strtod (const char*s,char **endp) | 將字符串s前綴轉換為double型 |
| 7 | long strtol(const char*s,char **endp,int base) | 將字符串s前綴轉換為long型 |
| 8 | unsinged long strtol(const char*s,char **endp,int base) | 將字符串s前綴轉換為 unsinged long型 |
| 9 | int rand(void) | 產生一個0~RAND_MAX之間的偽隨機數 |
| 10 | void srand(unsigned int seed) | 初始化隨機數發生器 |
| 11 | void *calloc(size_t nelem, size_t elsize) | 分配主存儲器 |
| 12 | void *malloc(unsigned size) | 內存分配函數 |
| 13 | void *realloc(void *ptr, unsigned newsize) | 重新分配主存 |
| 14 | void free(void *ptr) | 釋放已分配的塊 |
| 15 | void abort(void) | 異常終止一個進程 |
| 16 | void exit(int status) | 終止應用程序 |
| 17 | int atexit(atexit_t func) | 注冊終止函數 |
| 18 | char *getenv(char *envvar) | 從環境中取字符串 |
| 19 | void *bsearch(const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *)) | 二分法搜索函數 |
| 20 | void qsort(void *base, int nelem, int width, int (*fcmp)()) | 使用快速排序例程進行排序 |
| 21 | int abs(int i) | 求整數的絕對值 |
| 22 | long labs(long n) | 取長整型絕對值 |
| 23 | div_t div(int number, int denom) | 將兩個整數相除 , 返回商和余數 |
| 24 | ldiv_t ldiv(long lnumer, long ldenom) | 兩個長整型數相除 , 返回商和余數 |
五. <time.h>
| 1 | clock_t clock(void) | 確定處理器時間函數 |
| 2 | time_t time(time_t *tp) | 返回當前日歷時間 |
| 3 | double difftime(time_t time2, time_t time1) | 計算兩個時刻之間的時間差 |
| 4 | time_t mktime(struct tm *tp) | 將分段時間值轉換為日歷時間值 |
| 5 | char *asctime(const struct tm *tblock) | 轉換日期和時間為ASCII碼 |
| 6 | char *ctime(const time_t *time) | 把日期和時間轉換為字符串 |
| 7 | struct tm *gmtime(const time_t *timer) | 把日期和時間轉換為格林尼治標準時間 |
| 8 | struct tm *localtime(const time_t *timer) | 把日期和時間轉變為結構 |
| 9 | size_t strftime(char *s,size_t smax,const char *fmt, const struct tm *tp) | 根據 fmt 的格式 要求將 *tp中的日期與時間轉換為指定格式 |
六. <string.h>
| 1 | int bcmp(const void *s1, const void *s2, int n) | 比較字符串s1和s2的前n個字節是否相等 |
| 2 | void bcopy(const void *src, void *dest, int n) | 將字符串src的前n個字節復制到dest中 |
| 3 | void bzero(void *s, int n) | 置字節字符串s的前n個字節為零 |
| 4 | void *memccpy(void *dest, void *src, unsigned char ch, unsigned int count) | 由src所指內存區域復制不多于count個字節到dest所指內存區域,如果遇到字符ch則停止復制 |
| 5 | void *memcpy(void *dest, void *src, unsigned int count) | 由src所指內存區域復制count個字節到dest所指內存區域 |
| 6 | void *memchr(void *buf, char ch, unsigned count) | 從buf所指內存區域的前count個字節查找字符ch |
| 7 | int memcmp(void *buf1, void *buf2, unsigned int count) | 比較內存區域buf1和buf2的前count個字節 |
| 8 | int memicmp(void *buf1, void *buf2, unsigned int count) | 比較內存區域buf1和buf2的前count個字節但不區分字母的大小寫 |
| 9 | void *memmove(void *dest, const void *src, unsigned int count) | 由src所指內存區域復制count個字節到dest所指內存區域 |
| 10 | void *memset(void *buffer, int c, int count) | 把buffer所指內存區域的前count個字節設置成字符c |
| 11 | void setmem(void *buf, unsigned int count, char ch) | 把buf所指內存區域前count個字節設置成字符ch |
| 12 | void movmem(void *src, void *dest, unsigned int count) | 由src所指內存區域復制count個字節到dest所指內存區域 |
| 13 | char *stpcpy(char *dest,char *src) | 把src所指由NULL結束的字符串復制到dest所指的數組中 |
| 14 | char *strcpy(char *dest,char *src) | 把src所指由NULL結束的字符串復制到dest所指的數組中 |
| 15 | char *strcat(char *dest,char *src) | 把src所指字符串添加到dest結尾處(覆蓋dest結尾處的’\0’)并添加’\0’ |
| 16 | char *strchr(char *s,char c) | 查找字符串s中首次出現字符c的位置 |
| 17 | int strcmp(char *s1,char * s2) | 比較字符串s1和s2 |
| 18 | int stricmp(char *s1,char * s2) | 比較字符串s1和s2,但不區分字母的大小寫 |
| 19 | int stricmp(char *s1,char * s2) | 比較字符串s1和s2,但不區分字母的大小寫 |
| 20 | int strcspn(char *s1,char *s2) | 在字符串s1中搜尋s2中所出現的字符 |
| 21 | char *strdup(char *s) | 復制字符串s |
| 22 | int strlen(char *s) | 計算字符串s的長度 |
| 23 | char *strlwr(char *s) | 將字符串s轉換為小寫形式 |
| 24 | char *strupr(char *s) | 將字符串s轉換為大寫形式 |
| 25 | char *strncat(char *dest,char *src,int n) | 把src所指字符串的前n個字符添加到dest結尾處(覆蓋dest結尾處的’\0’)并添加’\0’ |
| 26 | int strcmp(char *s1,char * s2,int n) | 比較字符串s1和s2的前n個字符 |
| 27 | int strnicmp(char *s1,char * s2,int n) | 比較字符串s1和s2的前n個字符但不區分大小寫 |
| 28 | char *strncpy(char *dest, char *src, int n) | 把src所指由NULL結束的字符串的前n個字節復制到dest所指的數組中 |
| 29 | char *strpbrk(char *s1, char *s2) | 在字符串s1中尋找字符串s2中任何一個字符相匹配的第一個字符的位置,空字符NULL不包括在內 |
| 30 | char *strrev(char *s) | 把字符串s的所有字符的順序顛倒過來(不包括空字符NULL) |
| 31 | char *strset(char *s, char c) | 把字符串s中的所有字符都設置成字符c |
| 32 | char *strstr(char *haystack, char *needle) | 從字符串haystack中尋找needle第一次出現的位置(不比較結束符NULL) |
| 33 | char *strtok(char *s, char *delim) | 分解字符串為一組標記串。s為要分解的字符串,delim為分隔符字符串 |
| 34 | int strnicmp(char *s1,char * s2,int n) | 比較字符串s1和s2的前n個字符但不區分大小寫 |
文檔資料
上面只是簡單的介紹函數原型和功能,如果想對函數進一步了解可以下載以下文檔 (內含詳解與實例):
1. C語言標準函數庫速查手冊.chm
2. C語言標準函數庫詳解.pdf
總結
以上是生活随笔為你收集整理的C语言标准库函数大全(ctype、time 、stdio、stdlib、math、string)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机课程设计Servlet网上订餐系统
- 下一篇: 当按下ESC键时,关闭应用程序