atol() – atoll() —Convert Character String to Long or
Long Long Integer
IBM說明
The atol() function converts a character string to a long
value. The atoll() function converts a character string to a long long value.
The input string is a sequence of characters that can be interpreted as a numeric value of the specified return type. The function stops reading the input string at the first character that it cannot recognize as part of a number. This character can be the null character that ends the string.
(字串接受格式)
下列使用atol()為例,使用long 去接轉換後回傳值。
程式碼
- #include <stdlib.h>
- #include <stdio.h>
- int main(void)
- {
- char *strnumber = " 1234567890";
- long number_out;
- number_out = atol(strnumber);
- printf("number_in:\"%s\"\t,number_out:%ld\n", strnumber, number_out);
- }
執行結果
參考資料
沒有留言:
發佈留言