How to convert int to char string


How can I convert numbers that are combined with - into a string.

For example: 12-4-30

I need to make all those numbers including the - into one string.

I tried:

string 12-4-30;

but it doesn't seem to work.


A character is typically just that, one character. Not seven.

You can do a wide character:

char what = '12-4-30';

but I think that's more bits than most compilers will let you have in a char, so it's not going to work.

If you meant a string of character, you should use snprintf():

char what[32];

snprintf(what, sizeof what, "%d-%d-%d", 12, 4, 30);
printf("built string: '%s'\n", what);