atoi()
是C標準庫中的一個函數,用于將字符串轉換為整數。函數原型如下:
int atoi(const char *str);
參數 str
是一個指向要轉換的字符串的指針。atoi()
函數會嘗試將字符串中的數字部分轉換為整數,并返回轉換后的整數值。如果字符串中不僅包含數字,還包含其他非數字字符,atoi()
函數會盡可能地將數字部分解析為整數,并忽略后面的非數字字符。?
例如:
#include <stdio.h>
#include <stdlib.h>int main() {const char *str = "12345";int num = atoi(str);printf("Converted number: %d\n", num);return 0;
}
?