linux c 常用函式

2021-09-10 04:52:20 字數 791 閱讀 5832

int sprintf( char *buffer, const char *format [, argument] … );//spritnf 在大多數場合可以替代itoa

atoi //字串轉化為乙個整型值

itoa//int-->str  linux c沒有這個函式

size_t strlen(const char *s)

char *strcpy(char *dest,const char *src)//字串拷貝函式

char  *strcat(char *dest,const char *src)//把字串src連線到字串dest的後面

int strcmp(const char *s1,const char *s2)//相等 則返回0 不相等 則返回乙個大於零的數

extern char *strstr(char *str1, char *str2);//返回值:返回該位置的指標,如找不到,返回空指標sizeof是運算子,在標頭檔案中typedef為unsigned int,其值在編譯時即計算好了,引數可以是陣列、指標、型別、物件、函式等。strlen是函式,要在執行時才能計算。引數必須是字元型指標。當陣列名作為引數傳入時,實際上陣列就退化成指標了。變數初始化
memset(a, 0, sizeof(a));

memset(a, 0, n * sizeof(int));

int * p = (int *)malloc(sizeof(int)); //sizeof(int)返回值是int所佔的位元組數

Linux C 常用函式

open proc net dev o rdonly o excl lseek fd,0,seek set read fd,buf,sizeof buf 1 close fd strtok pdev,t r n 去除空格,製表符,換行符等不需要的字段 strstr buf,ath0 返回第一次指向a...

常用的Linux C函式介紹

需要標頭檔案 include 函式原型 int getopt int argc,char const argv const char optstring 函式返回值 如果找到符合的引數,則返回此引數字母,如果引數不包括在引數optstring的選項字母,則返回 字元,分析結束則返回 1 需要標頭檔案...

Linux C 函式總結

linux c 的記憶體分配 3個儲存空間動態分配和乙個記憶體釋放的函式 malloc 記憶體分配指定位元組儲存區,初始值不為0 calloc 為指定個數的具有指定長度的物件分配儲存空間,每一位初始化為0 reallco 更改以前的分配區長度 可增,可減 當增加時,將以前的分配區內容遷移到乙個足夠大...