2 回答

TA貢獻1963條經驗 獲得超6個贊
附加 gcc 參數 -lxxxx 方式調用提供 itoa 函數接口的庫。
不過你需要確定這個xxxx 應該是哪個才行。
你現在提示是 undefined reference 而不是提示函數未定義。所以應該代碼沒問題,是編譯環境的函數庫調用有問題。
你怎么裝的開發環境?不會是裝了頭文件沒裝對應 so 吧?

TA貢獻1824條經驗 獲得超6個贊
#include <stdlib.h>
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
long long atoq(const char *nptr);
linux下面沒對應的好像,我man 沒有查到.
給你直接找到一個實現,你放到自己代碼里面就可以了
void itoa ( unsigned long val, char *buf, unsigned radix )
{
char *p; /* pointer to traverse string */
char *firstdig; /* pointer to first digit */
char temp; /* temp char */
unsigned digval; /* value of digit */
p = buf;
firstdig = p; /* save pointer to first digit */
do {
digval = (unsigned) (val % radix);
val /= radix; /* get next digit */
/* convert to ascii and store */
if (digval > 9)
*p++ = (char ) (digval - 10 + 'a '); /* a letter */
else
*p++ = (char ) (digval + '0 '); /* a digit */
} while (val > 0);
/* We now have the digit of the number in the buffer, but in reverse
order. Thus we reverse them now. */
*p-- = '\0 '; /* terminate string; p points to last digit */
do {
temp = *p;
*p = *firstdig;
*firstdig = temp; /* swap *p and *firstdig */
--p;
++firstdig; /* advance to next two digits */
} while (firstdig < p); /* repeat until halfway */
}
- 2 回答
- 0 關注
- 136 瀏覽
添加回答
舉報