char *fgets(char *buf, int bufsize, FILE *stream);前端
從文件結構體指針stream中讀取數據,每次讀取一行。讀取的數據保存在buf指向的字符數組中,每次最多讀取bufsize-1個字符(第bufsize個字符賦'\0'),若是文件中的該行,不足bufsize個字符,則讀完該行就結束。如若該行(包括最後一個換行符)的字符數超過bufsize-1,則fgets只返回一個不完整的行,可是,緩衝區老是以NULL字符結尾,對fgets的下一次調用會繼續讀該行。函數成功將返回buf,失敗或讀到文件結尾返回NULL。所以咱們不能直接經過fgets的返回值來判斷函數是不是出錯而終止的,應該藉助feof函數或者ferror函數來判斷。數組
void exit(int status); (stdlib.h)函數
#include <string.h>ui
void *memset(void *s, int ch, size_t n);操作系統
void *memcpy(void *dest, const void *src, size_t n); 指針
int memcmp(const void *buf1, const void *buf2, unsigned int count);code
GetProcAddress() 檢索指定的動態連接庫(DLL)中的輸出庫函數地址。orm
#include <stdlib.h>htm
int *p = (int*)malloc(sizeof(int) * 1024);進程
分解字符串爲一組字符串。s爲要分解的字符,delim爲分隔符字符(若是傳入字符串,則傳入的字符串中每一個字符均爲分割符)。
首次調用時,s指向要分解的字符串,以後再次調用要把s設成NULL。
#include <string.h>
char s[] = "1,23|32|41|5";
char delims[] = ",";
char *result = NULL;
int num;
result = strtok(s, delims);
num = atoi(result);
char delims2[] = "|";
result = strtok(NULL, delims2);
while (NULL != result){
num = atoi(result);
result = strtok(NULL, delims2); // 順序很重要
}
atoi (表示 alphanumeric to integer)是把字符串轉換成整型的一個函數。
int sscanf(const char *buffer,const char *format,[argument ]...); // 從一個字符串中讀進與指定格式相符的數據(二進制)
int snprintf(char *str, size_t size, const char *format, ...); // 將可變個參數(...)按照format格式化成字符串,而後將其複製到str中
char
str[10]={0};
int
nLen=snprintf(str,sizof(str),
"0123456789012345678"
); //
str=012345678, nLen=19