_ltoa ()- 將長整數轉換為字串
格式
#include <stdlib.h>
char *_ltoa(long value, char *string, int radix);附註: _ltoa 函數僅支援 C++ ,不支援 C。
語言層次
分機
安全執行緒
是
說明
_ltoa 會將給定長整數 值 的數字轉換為以空值字元結尾的字串,並將結果儲存在 字串中。 radix 引數指定 value的基底; 它必須在 2 到 36 範圍內。 如果 基數 等於 10 且 值 是負數,則儲存字串的第一個字元是減號 (-)。
附註: 配置給 string 的空間必須夠大,才能保留傳回的字串。 此函數最多可以傳回 33 個位元組,包括空值字元 (\0)。
回覆值
_ltoa 會傳回指向 string的指標。 沒有錯誤回覆值。
當字串引數為 NULL 或 基數 超出範圍 2 至 36 時, errno 將設為 EINVAL。
範例
此範例會將整數值 -255L 轉換為十進位、二進位及十六進位值,並將其字元表示法儲存在陣列 緩衝區中。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buffer[35];
char *p;
p = _ltoa(-255L, buffer, 10);
printf("The result of _ltoa(-255) with radix of 10 is %s\n", p);
p = _itoa(-255L, buffer, 2);
printf("The result of _ltoa(-255) with radix of 2\n is %s\n", p);
p = _itoa(-255L, buffer, 16);
printf("The result of _ltoa(-255) with radix of 16 is %s\n", p);
return 0;
}輸出應該為: The result of _ltoa(-255) with radix of 10 is -255
The result of _ltoa(-255) with radix of 2
is 11111111111111111111111100000001
The result of _ltoa(-255) with radix of 16 is ffffff01