當前位置:首頁 » 編程語言 » c語言常用庫函數
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言常用庫函數

發布時間: 2022-06-10 01:35:31

1. c語言中的頭文件有多少種都有哪些C函數庫有哪些

iv_t和lldiv_t;宏例如EXIT_FAILURE、EXIT_SUCCESS、RAND_MAX和MB_CUR_MAX等等;

常見的函數有malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等。具體內容可以在編譯器的包含目錄stdlib.h頭文件中打開查看。

為了方便用戶編寫程序,C語言為用戶開發了大量的庫函數,定義在。H文件,用戶可以調用這些函數來實現強大的功能。因此,對於用戶來說,這些函數的使用是提高編程水平的關鍵。

(1)c語言常用庫函數擴展閱讀:

以下內容適用於頭文件

1.對於具有外部存儲類型的標識符,可以在任何其他源程序文件中聲明後引用它們,這樣用戶就可以完全將具有外部存儲類型的標識符的一些聲明放在頭文件中。

2.具體來說,頭文件可以包括用戶構造的數據類型(例如枚舉類型)、外部變數、外部函數、常量和具有一定通用性或公共量的內聯函數。一般的變數和函數定義不應該放在頭文件中。

其他:

雙假設(雙x,雙y);//給定一個直角三角形的兩條邊的長度,求斜邊的長度。

雙ldexp(雙x,int指數);//計算x*(2的指數次方)。

雙poly(Doublex,intdegree,Doublecoeffs[])//計算多項式。

Ntmatherr(structexception*e)//數學錯誤計算處理程序。

2. 能列舉些C語言中比較常見重要庫函數的用法嗎

memcpy
內存塊復制函數
memcpy(目標地址,源地址,復制的數據量);
舉例
long
s
=
1680324;
char
k[4];
memcpy(k,&s,sizeof(s));
就把s填充到k中了。

3. c語言常用庫函數有哪些

最低0.27元/天開通網路文庫會員,可在文庫查看完整內容>
原發布者:shimingtime
附錄CC語言常用的庫函數庫函數並不是C語言的一部分,它是由編譯系統根據一般用戶的需要編制並提供給用戶使用的一組程序。每一種C編譯系統都提供了一批庫函數,不同的編譯系統所提供的庫函數的數目和函數名以及函數功能是不完全相同的。ANSIC標准提出了一批建議提供的標准庫函數。它包括了目前多數C編譯系統所提供的庫函數,但也有一些是某些C編譯系統未曾實現的。考慮到通用性,本附錄列出ANSIC建議的常用庫函數。由於C庫函數的種類和數目很多,例如還有屏幕和圖形函數、時間日期函數、與系統有關的函數等,每一類函數又包括各種功能的函數,限於篇幅,本附錄不能全部介紹,只從教學需要的角度列出最基本的。讀者在編寫C程序時可根據需要,查閱有關系統的函數使用手冊。1.數學函數使用數學函數時,應該在源文件中使用預編譯命令:#include或#include"math.h"2.字元函數在使用字元函數時,應該在源文件中使用預編譯命令:#include或#include"ctype.h"3.字元串函數使用字元串中函數時,應該在源文件中使用預編譯命令:#include或#include"string.h"4.輸入輸出函數在使用輸入輸出函數時,應該在源文件中使用預編譯命令:#include或#include"stdio.h"5.動態存儲分配函數在使用動態存儲分配函數時,應該在源文件中使用預編譯命令:#include或#include"stdlib.h"6.其他函數有些函數由於不便歸入某一類,所以單獨列出。使用這些

4. C語言有哪幾種庫函數

int 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')
========數學函數(原型聲明所在頭文件為math.h、stdlib.h、string.h、float.h)===========
int abs(int i) 返回整型參數i的絕對值
double cabs(struct complex znum) 返回復數znum的絕對值
double fabs(double x) 返回雙精度參數x的絕對值
long labs(long n) 返回長整型參數n的絕對值
double exp(double x) 返回指數函數ex的值
double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存貯在eptr中
double ldexp(double value,int exp); 返回value*2exp的值
double log(double x) 返回logex的值
double log10(double x) 返回log10x的值
double pow(double x,double y) 返回xy的值
double pow10(int p) 返回10p的值
double sqrt(double x) 返回x的開方
double acos(double x) 返回x的反餘弦cos-1(x)值,x為弧度
double asin(double x) 返回x的反正弦sin-1(x)值,x為弧度
double atan(double x) 返回x的反正切tan-1(x)值,x為弧度
double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x為弧度
double cos(double x) 返回x的餘弦cos(x)值,x為弧度
double sin(double x) 返回x的正弦sin(x)值,x為弧度
double tan(double x) 返回x的正切tan(x)值,x為弧度
double cosh(double x) 返回x的雙曲餘弦cosh(x)值,x為弧度
double sinh(double x) 返回x的雙曲正弦sinh(x)值,x為弧度
double tanh(double x) 返回x的雙曲正切tanh(x)值,x為弧度
double hypot(double x,double y) 返回直角三角形斜邊的長度(z),
x和y為直角邊的長度,z2=x2+y2
double ceil(double x) 返回不小於x的最小整數
double floor(double x) 返回不大於x的最大整數
void srand(unsigned seed) 初始化隨機數發生器
int rand() 產生一個隨機數並返回這個數
double poly(double x,int n,double c[])從參數產生一個多項式
double modf(double value,double *iptr)將雙精度數value分解成尾數和階
double fmod(double x,double y) 返回x/y的余數
double frexp(double value,int *eptr) 將雙精度數value分成尾數和階
double atof(char *nptr) 將字元串nptr轉換成浮點數並返回這個浮點數
double atoi(char *nptr) 將字元串nptr轉換成整數並返回這個整數
double atol(char *nptr) 將字元串nptr轉換成長整數並返回這個整數
char *ecvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *fcvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *gcvt(double value,int ndigit,char *buf)
將數value轉換成字元串並存於buf中,並返回buf的指針
char *ultoa(unsigned long value,char *string,int radix)
將無符號整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *ltoa(long value,char *string,int radix)
將長整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *itoa(int value,char *string,int radix)
將整數value轉換成字元串存入string,radix為轉換時所用基數
double atof(char *nptr) 將字元串nptr轉換成雙精度數,並返回這個數,錯誤返回0
int atoi(char *nptr) 將字元串nptr轉換成整型數, 並返回這個數,錯誤返回0
long atol(char *nptr) 將字元串nptr轉換成長整型數,並返回這個數,錯誤返回0
double strtod(char *str,char **endptr)將字元串str轉換成雙精度數,並返回這個數,
long strtol(char *str,char **endptr,int base)將字元串str轉換成長整型數,
並返回這個數,
int matherr(struct exception *e)
用戶修改數學錯誤返回信息函數(沒有必要使用)
double _matherr(_mexcep why,char *fun,double *arg1p,
double *arg2p,double retval)
用戶修改數學錯誤返回信息函數(沒有必要使用)
unsigned int _clear87() 清除浮點狀態字並返回原來的浮點狀態
void _fpreset() 重新初使化浮點數學程序包
unsigned int _status87() 返回浮點狀態字
============目錄函數(原型聲明所在頭文件為dir.h、dos.h)================
int chdir(char *path) 使指定的目錄path(如:"C:\\WPS")變成當前的工作目錄,成
功返回0
int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功
返回0
pathname為指定的目錄名和文件名,如"C:\\WPS\\TXT"
ffblk為指定的保存文件信息的一個結構,定義如下:
┏━━━━━━━━━━━━━━━━━━┓
┃struct ffblk ┃
┃{ ┃
┃ char ff_reserved[21]; /*DOS保留字*/┃
┃ char ff_attrib; /*文件屬性*/ ┃
┃ int ff_ftime; /*文件時間*/ ┃
┃ int ff_fdate; /*文件日期*/ ┃
┃ long ff_fsize; /*文件長度*/ ┃
┃ char ff_name[13]; /*文件名*/ ┃
┃} ┃
┗━━━━━━━━━━━━━━━━━━┛
attrib為文件屬性,由以下字元代表
┏━━━━━━━━━┳━━━━━━━━┓
┃FA_RDONLY 只讀文件┃FA_LABEL 卷標號┃
┃FA_HIDDEN 隱藏文件┃FA_DIREC 目錄 ┃
┃FA_SYSTEM 系統文件┃FA_ARCH 檔案 ┃
┗━━━━━━━━━┻━━━━━━━━┛
例:
struct ffblk ff;
findfirst("*.wps",&ff,FA_RDONLY);

int findnext(struct ffblk *ffblk) 取匹配finddirst的文件,成功返回0
void fumerge(char *path,char *drive,char *dir,char *name,char *ext)
此函數通過盤符drive(C:、A:等),路徑dir(\TC、\BC\LIB等),
文件名name(TC、WPS等),擴展名ext(.EXE、.COM等)組成一個文件名
存與path中.
int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)
此函數將文件名path分解成盤符drive(C:、A:等),路徑dir(\TC、\BC\LIB等),
文件名name(TC、WPS等),擴展名ext(.EXE、.COM等),並分別存入相應的變數中.
int getcurdir(int drive,char *direc) 此函數返回指定驅動器的當前工作目錄名稱
drive 指定的驅動器(0=當前,1=A,2=B,3=C等)
direc 保存指定驅動器當前工作路徑的變數 成功返回0
char *getcwd(char *buf,iint n) 此函數取當前工作目錄並存入buf中,直到n個字
節長為為止.錯誤返回NULL
int getdisk() 取當前正在使用的驅動器,返回一個整數(0=A,1=B,2=C等)
int setdisk(int drive) 設置要使用的驅動器drive(0=A,1=B,2=C等),
返回可使用驅動器總數
int mkdir(char *pathname) 建立一個新的目錄pathname,成功返回0
int rmdir(char *pathname) 刪除一個目錄pathname,成功返回0
char *mktemp(char *template) 構造一個當前目錄上沒有的文件名並存於template中
char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路徑,
,此函數使用DOS的PATH變數,未找到文件返回NULL
===========進程函數(原型聲明所在頭文件為stdlib.h、process.h)===========
void abort() 此函數通過調用具有出口代碼3的_exit寫一個終止信息於stderr,
並異常終止程序。無返回值
int exec…裝入和運行其它程序
int execl( char *pathname,char *arg0,char *arg1,…,char *argn,NULL)
int execle( char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[])
int execlp( char *pathname,char *arg0,char *arg1,…,NULL)
int execlpe(char *pathname,char *arg0,char *arg1,…,NULL,char *envp[])
int execv( char *pathname,char *argv[])
int execve( char *pathname,char *argv[],char *envp[])
int execvp( char *pathname,char *argv[])
int execvpe(char *pathname,char *argv[],char *envp[])
exec函數族裝入並運行程序pathname,並將參數
arg0(arg1,arg2,argv[],envp[])傳遞給子程序,出錯返回-1
在exec函數族中,後綴l、v、p、e添加到exec後,
所指定的函數將具有某種操作能力
有後綴 p時,函數可以利用DOS的PATH變數查找子程序文件。
l時,函數中被傳遞的參數個數固定。
v時,函數中被傳遞的參數個數不固定。
e時,函數傳遞指定參數envp,允許改變子進程的環境,
無後綴e時,子進程使用當前程序的環境。

void _exit(int status)終止當前程序,但不清理現場
void exit(int status) 終止當前程序,關閉所有文件,寫緩沖區的輸出(等待輸出),
並調用任何寄存器的"出口函數",無返回值

int spawn…運行子程序
int spawnl( int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL)
int spawnle( int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[])
int spawnlp( int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL)
int spawnlpe(int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[])
int spawnv( int mode,char *pathname,char *argv[])
int spawnve( int mode,char *pathname,char *argv[],char *envp[])
int spawnvp( int mode,char *pathname,char *argv[])
int spawnvpe(int mode,char *pathname,char *argv[],char *envp[])
spawn函數族在mode模式下運行子程序pathname,並將參數
arg0(arg1,arg2,argv[],envp[])傳遞給子程序.出錯返回-1
mode為運行模式
mode為 P_WAIT 表示在子程序運行完後返回本程序
P_NOWAIT 表示在子程序運行時同時運行本程序(不可用)
P_OVERLAY表示在本程序退出後運行子程序
在spawn函數族中,後綴l、v、p、e添加到spawn後,
所指定的函數將具有某種操作能力
有後綴 p時, 函數利用DOS的PATH查找子程序文件
l時, 函數傳遞的參數個數固定.
v時, 函數傳遞的參數個數不固定.
e時, 指定參數envp可以傳遞給子程序,允許改變子程序運行環境.
當無後綴e時,子程序使用本程序的環境.

int system(char *command) 將MSDOS命令command傳遞給DOS執行
======轉換子程序(函數原型所在頭文件為math.h、stdlib.h、ctype.h、float.h)========
char *ecvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *fcvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *gcvt(double value,int ndigit,char *buf)
將數value轉換成字元串並存於buf中,並返回buf的指針
char *ultoa(unsigned long value,char *string,int radix)
將無符號整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *ltoa(long value,char *string,int radix)
將長整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *itoa(int value,char *string,int radix)
將整數value轉換成字元串存入string,radix為轉換時所用基數
double atof(char *nptr) 將字元串nptr轉換成雙精度數,並返回這個數,錯誤返回0
int atoi(char *nptr) 將字元串nptr轉換成整型數, 並返回這個數,錯誤返回0
long atol(char *nptr) 將字元串nptr轉換成長整型數,並返回這個數,錯誤返回0
double strtod(char *str,char **endptr)將字元串str轉換成雙精度數,並返回這個數,
long strtol(char *str,char **endptr,int base)將字元串str轉換成長整型數,
並返回這個數,
int toascii(int c) 返回c相應的ASCII
int tolower(int ch) 若ch是大寫字母('A'-'Z')返回相應的小寫字母('a'-'z')
int _tolower(int ch) 返回ch相應的小寫字母('a'-'z')
int toupper(int ch) 若ch是小寫字母('a'-'z')返回相應的大寫字母('A'-'Z')
int _toupper(int ch) 返回ch相應的大寫字母('A'-'Z')

5. c語言裡面的庫函數是什麼一個概念

  1. 庫函數:顧名思義是把函數放到庫里..是別人把一些常用到的函數編完放到一個文件里,供別人用.別人用的時候把它所在的文件名用#include<>加到裡面就可以了.一般是放到lib文件里的。

  2. 一般是指編譯器提供的可在c源程序中調用的函數。可分為兩類一類是c語言標准規定的庫函數一類是編譯器特定的庫函數。

  3. 由於版權原因庫函數的源代碼一般是不可見的但在頭文件中你可以看到它對外的介面。什麼是庫函數語言的語句十分簡單如果要使用語言的語句直接計算sin或cos函數就需要編寫頗為復雜的程序。因為語言的語句中沒有提供直接計算sin或cos函數的語句。又如為了顯示一段文字我們在語言中也找不到顯示語句只能使用庫函數printf。

  4. 語言的庫函數並不是語言本身的一部分它是由編譯程序根據一般用戶的需要編制並提供用戶使用的一組程序。的庫函數極大地方便了用戶同時也補充了語言本身的不足。事實上在編寫語言程序時應當盡可能多地使用庫函數這樣既可以提高程序的運行效率又可以提高編程的質量。

6. 求 c語言庫函數表

常用的(1)I/O 函數。包括各種控制台I/O、緩沖型文件I/O和UNIX式非緩沖型文件I/O操作。 需要的包含文件:stdio.h 例如: getchar,putchar,printf,scanf,fopen,fclose,fgetc,fgets,fprintf,fsacnf,fputc,fputs,fseek,fread,fwrite等。 (2)字元串、內存和字元函數。包括對字元串進行各種操作和對字元進行操作的函數。 需要的包含文件:string.h、mem.h、ctype.h或string.h 例如:用於檢查字元的函數:isalnum,isalpha,isdigit,islower,isspace等。用於字元串操作函數:strcat,strchr,strcmp,strcpy,strlen,strstr等。 (3)數學函數。包括各種常用的三角函數、雙曲線函數、指數和對數函數等。 需要的包含文件:math.h 例如:sin,cos,exp(e的x次方),log,sqrt(開平方),pow(x的y次方)等。 (4)時間、日期和與系統有關的函數。對時間、日期的操作和設置計算機系統狀態等。 需要的包含文件:time.h 例如:time返回系統的時間;asctime返回以字元串形式表示的日期和時間。 (5)動態存儲分配。包括"申請分配"和"釋放"內存空間的函數。 需要的包含文件:alloc.h或stdlib.h 例如:calloc,free,malloc,realloc等。

7. C語言中什麼是庫函數

庫函數(Library function)是把函數放到庫里,供別人使用的一種方式。.方法是把一些常用到的函數編完放到一個文件里,供不同的人進行調用。調用的時候把它所在的文件名用#include>加到裡面就可以了。一般是放到lib文件里的。
一般是指編譯器提供的可在c源程序中調用的函數。可分為兩類,一類是c語言標准規定的庫函數,一類是編譯器特定的庫函數。
由於版權原因,庫函數的源代碼一般是不可見的,但在頭文件中你可以看到它對外的介面

庫函數簡介。
C語言的語句十分簡單,如果要使用C語言的語句直接計算sin或cos函數,就需要編寫頗為復雜的程序。因為C語言的語句中沒有提供直接計算sin或cos函數的語句。又如為了顯示一段文字,我們在C語言中也找不到顯示語句,只能使用庫函數printf。
C語言的庫函數並不是C語言本身的一部分,它是由編譯程序根據一般用戶的需要編制並提供用戶使用的一組程序。C的庫函數極大地方便了用戶,同時也補充了C語言本身的不足。事實上,在編寫C語言程序時,應當盡可能多地使用庫函數,這樣既可以提高程序的運行效率,又可以提高編程的質量。
這里調用的是靜態庫。
函數庫:函數庫是由系統建立的具有一定功能的函數的集合。庫中存放函數的名稱和對應的目標代碼,以及連接過程中所需的重定位信息。用戶也可以根據自己的需要建立自己的用戶函數庫。
庫函數:存放在函數庫中的函數。庫函數具有明確的功能、入口調用參數和返回值。
連接程序:將編譯程序生成的目標文件連接在一起生成一個可執行文件。
頭文件:有時也稱為包含文件。C語言庫函數與用戶程序之間進行信息通信時要使用的數據和變數,在使用某一庫函數時,都要在程序中嵌入(用#include)該函數對應的頭文件。
由於C語言編譯系統應提供的函數庫尚無國際標准。不同版本的C語言具有不同的庫函數,用戶使用時應查閱有關版本的C的庫函數參考手冊。我們以Turbo C為例簡介一下C的庫函數,並附錄中給出了Turbo C的部分常用庫函數。

8. 什麼是C語言標准函數庫平常用的哪些函數屬於標准函數庫

你會發現,有一些頭文件(比如stdlib.h,stdio.h)每一個編譯器都有,而裡面的函數(如printf,malloc)每一個編譯器都支持。這些函數組成的集合就是標准函數庫。平常用的函數基本都屬於標准函數庫。
ANSI對此是有規定的

9. C語言字元串處理的庫函數有哪些

函數名: strrchr
功 能: 在串中查找指定字元的最後一個出現
用 法: char *strrchr(char *str, char c);
舉例:
[cpp] view plain
char fullname="./lib/lib1.so";
char *ptr;
ptr = strrchr(fullname,'/');
printf("filename is %s",++ptr);
//運行結果:filename is lib1.so

函數名: strchr
功 能: 在串中查找指定字元的第一個出現
用 法: char *strchr(char *str, char c);
舉例:
[cpp] view plain
char fullname="./lib/lib1.so";
char *ptr;
ptr = strrchr(fullname,'.');
printf("after strchr() is %s",++ptr);
//運行結果:after strchr() is /lib/lib1.so

函數名: strtok
功 能: 在串中查找指定字元的第一個出現
用 法: char *strtok(char *s, char *delim);
說明:
1.strtok函數的實質上的處理是,strtok在s中查找包含在delim中的字元並用NULL(』/0′)來替換,直到找遍整個字元串。這句話有兩層含義:(1)每次調用strtok函數只能獲得一個分割單位。(2)要獲得所有的分割單元必須反復調用strtok函數。
2.strtok函數以後的調用時的需用NULL來替換s.
3.形參s(要分割的字元串)對應的變數應用char s[]=」….」形式,而不能用char *s=」….」形式。
舉例:
[cpp] view plain
void main()
{
char buf[]=」Golden Global View」;
char* token = strtok( buf, 」 「);
while( token != NULL )
{
printf( 」%s 「, token );
token = strtok( NULL, 」 「);
}
return 0;
}
/*其結果為:

Golden
Global
View
*/

函數名:strncpy
功能:把src所指由NULL結束的字元串的前n個位元組復制到dest所指的數組中
用法:char *strncpy(char *dest, char *src, int n);
說明:
如果src的前n個位元組不含NULL字元,則結果不會以NULL字元結束。
如果src的長度小於n個位元組,則以NULL填充dest直到復制完n個位元組。
src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字元串。
返回指向dest的指針。
舉例:
[c-sharp] view plain
#include <syslib.h>
#include <string.h>

main()
{
char buf[4];
char *s="abcdefg";

strncpy(buf,s,4);
printf("%s/n",buf);
return 0;
}
/*運行結果:
abcd
*/

函數名: stpcpy
功 能: 拷貝一個字元串到另一個
用 法: char *stpcpy(char *destin, char *source);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s/n", string);
return 0;
}
/*運行結果
abcdefghi
*/

函數名: strcat
功 能: 字元串拼接函數
用 法: char *strcat(char *destin, char *source);
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s/n", destination);
return 0;
}
/*運行結果:
Borland C++
*/

函數名: strcmp
功 能: 串比較
用 法: int strcmp(char *str1, char *str2);
看Asic碼,str1>str2,返回值 > 0;兩串相等,返回0
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else if(ptr < 0)
printf("buffer 2 is less than buffer 1/n");
else
printf("buffer 2 is equal with buffer 1/n");
return 0;
}
/*運行結果:
buffer 2 is greater than buffer 1
*/

函數名: strncmpi
功 能: 將一個串中的一部分與另一個串比較, 不管大小寫
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}

函數名: strcspn
功 能: 在串中查找第一個給定字元集內容的段
用 法: int strcspn(char *str1, char *str2);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;
length = strcspn(string1, string2);
printf("Character where strings intersect is at position %d/n", length);
return 0;
}

函數名: strp
功 能: 將串拷貝到新建的位置處
用 法: char *strp(char *str);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *p_str, *string = "abcde";
p_str = strp(string);
printf("%s/n", p_str);
free(p_str);
return 0;
}

函數名: stricmp
功 能: 以大小寫不敏感方式比較兩個串
用 法: int stricmp(char *str1, char *str2);
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = stricmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}

函數名: strerror
功 能: 返回指向錯誤信息字元串的指針
用 法: char *strerror(int errnum);
舉例:
[cpp] view plain
#include <stdio.h>
#include <errno.h>
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s/n", buffer);
return 0;
}

函數名: strncmp
功 能: 串比較
用 法: int strncmp(char *str1, char *str2, int maxlen);
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return(0);
}

函數名: strncmpi
功 能: 把串中的一部分與另一串中的一部分比較, 不管大小寫
用 法: int strncmpi(char *str1, char *str2, int len);
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}

函數名: strnset
功 能: 將一個串中的所有字元都設為指定字元
用 法: char *strnset(char *str, char ch, unsigned n);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
printf("string before strnset: %s/n", string);
strnset(string, letter, 13);
printf("string after strnset: %s/n", string);
return 0;
}

函數名: strpbrk
功 能: 在串中查找給定字元集中的字元
用 法: char *strpbrk(char *str1, char *str2);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr;
ptr = strpbrk(string1, string2);
if (ptr)
printf("strpbrk found first character: %c/n", *ptr);
else
printf("strpbrk didn't find character in set/n");
return 0;
}

函數名: strrev
功 能: 串倒轉
用 法: char *strrev(char *str);
舉例:
[cpp] view plain
#include <string.h>
#include <stdio.h>
int main(void)
{
char *forward = "string";
printf("Before strrev(): %s/n", forward);
strrev(forward);
printf("After strrev(): %s/n", forward);
return 0;
}
/*運行結果:
Before strrev(): string
After strrev(): gnirts
*/

函數名: strstr
功 能: 在串中查找指定字元串的第一次出現
用 法: char *strstr(char *str1, char *str2);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s/n", ptr);
return 0;
}

函數名: strtod
功 能: 將字元串轉換為double型值
用 法: double strtod(char *str, char **endptr);
舉例:
[cpp] view plain
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char input[80], *endptr;
double value;
printf("Enter a floating point number:");
gets(input);
value = strtod(input, &endptr);
printf("The string is %s the number is %lf/n", input, value);
return 0;
}

函數名: strtol
功 能: 將串轉換為長整數
用 法: long strtol(char *str, char **endptr, int base);
舉例:
[cpp] view plain
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char *string = "87654321", *endptr;
long lnumber;
/* strtol converts string to long integer */
lnumber = strtol(string, &endptr, 10);
printf("string = %s long = %ld/n", string, lnumber);
return 0;
}

函數名: strupr
功 能: 將串中的小寫字母轉換為大寫字母
用 法: char *strupr(char *str);
舉例:
[cpp] view plain
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;
/* converts string to upper case characters */
ptr = strupr(string);
printf("%s/n", ptr);
return 0;
}