alias
itoa() (C)
alias lang_id
c
how to
convert integer to string
lang_id
c
qid
29002

How to
itoa() (C)

Redirected to “convert integer to string

sprintf

Use sprintf function like sprintf(s, "%d", x).

#include <stdio.h>

void main() {
    char s[256];
    sprintf(s, "%d", 3);
    puts(s);    /* 3 */
}

atoi

Use atoi function (non-standard extension to the standard C).

void atoi(
    int value,
    char *buffer,
    int radix
);

Example:

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

void main() {
    char s[256];
    itoa(300, s, 10);

    puts(s);  /* 300 */
}
Select default language: