-
atoi
鎖定
- 外文名
- atoi
- 參 數
- 字符串
- 返回值
- int
- 適用語言
- C/C++
- 頭文件
- #include <stdlib.h>
atoi簡介
atoiC語言庫函數名
atoi
atoi原型
int atoi(const char *nptr);
atoiUNICODE
_wtoi()
atoi例子
(1)
//vs2013裏調用printf函數請使用預處理命令#define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> int main(void) { int n; char *str = "12345.67"; n = atoi(str); printf("n=%d\n",n); return 0; }
輸出:
n = 12345
(2)
//vs2013裏調用printf函數請使用預處理命令#define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> int main() { char a[] = "-100"; char b[] = "123"; int c; c = atoi(a) + atoi(b); printf("c=%d\n", c); return 0; }
執行結果:
c = 23
- 參考資料
-
- 1. C語言atoi()函數:將字符串轉換成int(整數) .C語言中文網[引用日期2016-08-06]