itoa() is a really handy function to convert a number to a string. Linux does not seem to have itoa(), is there an equivalent function or do I have to use sprintf(str, '%d', num)?
itoa() is a really handy function to convert a number to a string. Linux
Share
EDIT: Sorry, I should have remembered that this machine is decidedly non-standard, having plugged in various non-standard
libcimplementations for academic purposes 😉As
itoa()is indeed non-standard, as mentioned by several helpful commenters, it is best to usesprintf(target_string,"%d",source_int)or (better yet, because it’s safe from buffer overflows)snprintf(target_string, size_of_target_string_in_bytes, "%d", source_int). I know it’s not quite as concise or cool asitoa(), but at least you can Write Once, Run Everywhere ™ 😉Here’s the old (edited) answer
You are correct in stating that the default
gcc libcdoes not includeitoa(), like several other platforms, due to it not technically being a part of the standard. See here for a little more info. Note that you have toOf course you already know this, because you wanted to use
itoa()on Linux after presumably using it on another platform, but… the code (stolen from the link above) would look like:Example
Output: