Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下に示すように、2 つの変数を宣言して初期化しました。
int a=5; char* str; str = (char*)calloc(255, sizeof(char));
標準 C で int を char* に変換したいのですが、C++ の itoa などの変換関数を使用できません。
Ubuntu 11.10 を使用しています
まず第一にitoa、C++ のことではありません。
itoa
あなたは単に使用することができますsprintf:
sprintf
sprintf(str, "%d", a)
ただし、実際のアプリケーションsnprintfでは、バッファ オーバーフローのリスクを取り除くために使用する必要があります。
snprintf
str = malloc(16); snprintf(str, 16, "%d", a);
また、整数を格納するには 15 文字で十分です。