在 C 語言中可以呼叫 atoi( ) 將字串轉成數字;

但要將數字轉成字串的話並沒有內建的函數可以使用,
也許有人會建議可以使用 itoa( )  函數,
但 itoa( ) 並非標準函式庫,必須引用 Borland C/C++ 自行定義的 conio.h
所以在像 Unix/Linux 等環境便派不上用場。

但其實可以透過 sprintf( ) 來幫你把數字填到字串中:

#include <stdio.h>
#include <stdlib.h>

int main() {
-char *str;
-int num = 66;

-sprintf(str, "%d", num);
-printf("str = %s\n", str);

-return(0);
}
文章標籤
全站熱搜
創作者介紹
創作者 matis 的頭像
matis

Never give up

matis 發表在 痞客邦 留言(1) 人氣(15,444)