C語言常用庫函式
1 字元處理 ctype.h 2 數學函式 math.h 3 輸入輸出 stdio.h 4 實用工具程式 stdlib.h 5 字串處理 string.h
程式應包含在math.h |
||||||
函式型別 |
函式形式 |
功能 |
型別 |
|||
數 學 函 數 |
abs(int i) |
求整數的絕對值 |
int |
|||
fabs(double x) |
返回浮點數的絕對值 |
double |
||||
floor(double x) |
向下取整 |
double |
||||
ceil(double x) |
向上取整 |
double |
||||
trunc(double x) |
取整數部分 |
int |
||||
round(double x) |
四捨五入 |
int |
||||
fmod(double x, double y) |
計算x對y的模, 即x/y的餘數 |
double |
||||
int(double x) |
取整數部分 |
|
||||
exp(double x) |
指數函式 |
double |
||||
log(double x) |
對數函式ln(x) |
double |
||||
log10(double x) |
對數函式log |
double |
||||
labs(long n) |
取長整型絕對值 |
long |
||||
modf(double value, double *iptr) |
把數分為指數和尾數 |
double |
||||
pow(double x, double y) |
指數函式(x的y次方) |
double |
||||
sqrt(double x) |
計算平方根 |
double |
||||
rand() |
產生0到RAND_MAX之間的隨機整數32767 |
int |
||||
sin(double x) |
正弦函式 |
double |
||||
asin(double x) |
反正弦函式 |
double |
||||
sinh(double x) |
雙曲正弦函式 |
double |
||||
cos(double x); |
餘弦函式 |
double |
||||
acos(double x) |
反餘弦函式 |
double |
||||
cosh(double x) |
雙曲餘弦函式 |
double |
||||
tan(double x) |
正切函式 |
double |
||||
atan(double x) |
反正切函式 |
double |
||||
tanh(double x) |
雙曲正切函式 |
double |
||||
程式應包含在ctype.h |
||||||
函式型別 |
函式形式 |
功能 |
型別 |
|||
字 符 函 數 |
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') |
int |
||||
|
|
|
|
|||
程式應包含在string.h |
||||||
函式型別 |
函式形式 |
功能 |
型別 |
|||
字 符 串 函 數 |
strcat(char *dest,const char *src) |
將字串src新增到dest末尾 |
char |
|||
strchr(const char *s,int c) |
檢索並返回字元c在字串s中第一次出現的位置 |
char |
||||
strcmp(const char *s1,const char *s2) |
比較字串s1與s2的大小,並返回s1-s2 |
int |
||||
stpcpy(char *dest,const char *src) |
將字串src複製到dest |
char |
||||
strdup(const char *s) |
將字串s複製到最近建立的單元 |
char |
||||
strlen(const char *s) |
返回字串s的長度 |
int |
||||
strlwr(char *s) |
將字串s中的大寫字母全部轉換成小寫字母,並返回轉換後的字串 |
char |
||||
strrev(char *s) |
將字串s中的字元全部顛倒順序重新排列,並返回排列後的字串 |
char |
||||
strset(char *s,int ch) |
將一個字串s中的所有字元置於一個給定的字元ch |
char |
||||
strspn(const char *s1,const char *s2) |
掃描字串s1,並返回在s1和s2中均有的字元個數 |
char |
||||
strstr(const char *s1,const char *s2) |
描字串s2,並返回第一次出現s1的位置 |
char |
||||
strtok(char *s1,const char *s2) |
檢索字串s1,該字串s1是由字串s2中定義的定界符所分隔 |
char |
||||
strupr(char *s) |
將字串s中的小寫字母全部轉換成大寫字母,並返回轉換後的字串 |
char |
||||
序應包含在stdio.h |
||||||
函式型別 |
函式形式 |
功能 |
型別 |
|||
輸
入
輸
出
函
數 |
getch() |
從控制檯(鍵盤)讀一個字元,不顯示在螢幕上 |
int |
|||
putch() |
向控制檯(鍵盤)寫一個字元 |
int |
||||
getchar() |
從控制檯(鍵盤)讀一個字元,顯示在螢幕上 |
int |
||||
putchar() |
向控制檯(鍵盤)寫一個字元 |
int |
||||
getc(FILE *stream) |
從流stream中讀一個字元,並返回這個字元 |
int |
||||
putc(int ch,FILE *stream) |
向流stream寫入一個字元ch |
int |
||||
getw(FILE *stream) |
從流stream讀入一個整數,錯誤返回EOF |
int |
||||
putw(int w,FILE *stream) |
向流stream寫入一個整數 |
int |
||||
fclose(handle) |
關閉handle所表示的檔案處理 |
FILE * |
||||
fgetc(FILE *stream) |
從流stream處讀一個字元,並返回這個字元 |
int |
||||
fputc(int ch,FILE *stream) |
將字元ch寫入流stream中 |
int |
||||
fgets(char *string,int n,FILE *stream) |
流stream中讀n個字元存入string中 |
c har * |
||||
fopen(char *filename,char *type) |
開啟一個檔案filename,開啟方式為type,並返回這個檔案指標,type可為以下字串加上字尾 |
FILE * |
||||
fputs(char *string,FILE *stream) |
將字串string寫入流stream中 |
int |
||||
fread(void *ptr,int size,int nitems,FILE *stream) |
從流stream中讀入nitems個長度為size的字串存入ptr中 |
int |
||||
fwrite(void *ptr,int size,int nitems,FILE *stream) |
向流stream中寫入nitems個長度為size的字串,字串在ptr中 |
int |
||||
fscanf(FILE *stream,char *format[,argument,…]) |
以格式化形式從流stream中讀入一個字串 |
int |
||||
fprintf(FILE *stream,char *format[,argument,…]) |
以格式化形式將一個字串寫給指定的流stream |
int |
||||
scanf(char *format[,argument…]) |
從控制檯讀入一個字串,分別對各個引數進行賦值,使用BIOS進行輸出 |
int |
||||
printf(char *format[,argument,…])
|
傳送格式化字串輸出給控制檯(顯示器),使用BIOS進行輸出 |
int |
||||