C語言常用函式

2021-10-06 03:47:16 字數 943 閱讀 2460

1.atoi函式,將命令列輸入的字串常數轉為整型。在#include中。

2.strtok函式,將一串字串分隔。#include中

注意上面str為null時是從上一次停止位置的後面開始的。

例如:

#include

#include

intmain

(void

)printf

("after split,the str= %s\n"

,str)

;return0;

}

其執行結果為:

strtol()會將nptr指向的字串,根據引數base,按權轉化為long int, 然後返回這個值。

參考:4.strstr(str1,str2) 函式

定義:strstr(str1,str2) 函式用於判斷字串str2是否是str1的子串。如果是,則該函式返回str2在str1中首次出現的位址;否則,返回null。

比如:char str2 = 「cdef」;

char str1 = 「abcdefgh」;

則通過函式,將返回

strstr(str1,str2) = cdefgh;

如果str1不包含有str2。

char str2 = 「cxef」;

char str1 = 「abcdefgh」;

則通過函式,將返回

strstr(str1,str2) = null;

C語言常用函式

字串操作函式 記憶體操作函式 file fopen char filename,char type int fclose file stream 返回非0值關閉成功 開啟方式 說明 r 以 唯讀 方式開啟檔案。只允許讀取,不允許寫入。檔案必須存在,否則開啟失敗。w 以 寫入 方式開啟檔案。如果檔案不...

C語言mysql常用函式

c語言操作mysql資料 常用函式 所需標頭檔案 include 功能 獲得或初始化乙個mysql結構 函式原型 mysql mysql init mysql mysql 函式返回值 乙個被始化的mysql 控制代碼 備註 在記憶體不足的情況下,返回null 所需標頭檔案 include 函式原型 ...

C語言之常用函式

include include 常見的函式 引數 argc 引數的個數 argv 執行的引數列表 main函式 int main int argc,char const argv printf函式 printf test n scanf函式 int num scanf d num 錯誤,scanf只...