You can use sprintf
to do it, or maybe snprintf
if you have it:
char str[ENOUGH];
sprintf(str, "%d", 42);
Where the number of characters (plus terminating char) in the str
can be calculated using:
(int)((ceil(log10(num))+1)*sizeof(char))
More Related Contents:
- How to convert integer to string in C? [duplicate]
- How can I convert an int to a string in C?
- read specific number of chars in c [closed]
- isnt everything where it should be, why the segmentation fault?
- How can I get a text file into a string but whith the “\n” in C?
- Removing trailing newline character from fgets() input
- How do you allow spaces to be entered using scanf?
- How can I convert a std::string to int?
- How do I concatenate two strings in C?
- How does concatenation of two string literals work?
- Catch and compute overflow during multiplication of two large integers
- Check substring exists in a string in C
- How to dynamically allocate memory space for a string and get that string from user?
- How do you convert a byte array to a hexadecimal string in C?
- How to read string from keyboard using C?
- What do numbers using 0x notation mean?
- SIMD signed with unsigned multiplication for 64-bit * 64-bit to 128-bit
- Looking for a good hash table implementation in C [closed]
- How do you store an arbitrarily large integer value in memory?
- Tokenizing strings in C
- Why doesn’t scanf need an ampersand for strings and also works fine in printf (in C)?
- Why do we define INT_MIN as -INT_MAX – 1? [duplicate]
- How do I print a non-null-terminated string using printf?
- string array with garbage character at end
- Why does “memset(arr, -1, sizeof(arr)/sizeof(int))” not clear an integer array to -1?
- Modify a string with pointer [duplicate]
- Is there any reason not to use fixed width integer types (e.g. uint8_t)?
- realloc(): invalid next size when reallocating to make space for strcat on char * [duplicate]
- C usual arithmetic conversions
- How to concatenate string and int in C?