C語言atoi 函式

2021-10-13 16:00:08 字數 447 閱讀 5057

int atoi(const char *str)把引數str所指向的字串轉換為乙個整數(型別為 int 型)。

下面是 atoi() 函式的宣告。

int atoi(const char *str)
該函式返回轉換後的長整數,如果沒有執行有效的轉換,則返回零。

下面的例項演示了 atoi() 函式的用法。

#include #include #include //包含atoi()函式

int main(void)

列印結果:

**分析:

atoi()函式作用是把字串轉換成整數int型別,如果字串裡面的是數字返回數字、是字元則返回為0。

以上就是atoi()函式使用方式以及說明!

C語言atoi函式

c語言提供了一系列函式把字串轉換為整數 atoi atol atoll和atoq。include int atoi const char nptr long atol const char nptr long long atoll const char nptr long long atoq con...

C語言函式 atoi

c語言函式 atoi 函式說明 atoi 函式會掃瞄引數 str 字串,跳過前面的空白字元 例如空格,tab縮排等,可以通過isspace 函式來檢測 直到遇上數字或正負符號才開始做轉換,而再遇到非數字或字串結束時 0 才結束轉換,並將結果返回。返回值 返回轉換後的整型數 如果 str 不能轉換成 ...

atoi 函式的實現 C語言

atoi函式 原型 int atoi const char pstr 用法 將字串轉換成整型數 atoi 會掃瞄引數sptr字串,跳過前面的空格字元,直到遇到數字或正負號才開始做轉換,而再遇到非數字或字串時 0 才結束轉換,並將結果返回。程式 int my atoi char pstr 跳過前面的空...