strfromf, strfromd, strfromld

From cppreference.com
< c‎ | string‎ | byte
Defined in header <stdlib.h>
int strfromf( char *restrict s, size_t n, const char *restrict format, float fp );
(since C23)
int strfromd( char *restrict s, size_t n, const char *restrict format, double fp );
(since C23)
int strfroml( char *restrict s, size_t n, const char *restrict format, long double fp );
(since C23)

Converts a floating-point value to a byte string.

The functions are equivalent to snprintf(s, n, format, fp), except that the format string shall only contain the character %, an optional precision that does not contain an asterisk *, and one of the conversion specifiers a, A, e, E, f, F, g, or G, which applies to the type double, float, or long double) indicated by the function suffix (rather than by a length modifier). Use of these functions with any other format string results in undefined behavior.

Parameters

s - pointer to a character string to write to
n - up to n - 1 characters may be written, plus the null terminator
format - pointer to a null-terminated byte string specifying how to interpret the data
fp - floating-point value to convert

Return value

The number of characters that would have been written had n been sufficiently large, not counting the terminating null character. Thus, the null-terminated output has been completely written if and only if the returned value is both nonnegative and less than n.

Example

Reference

  • C23 standard (ISO/IEC 9899:2023):
  • 7.24.1.3 The strfromd, strfromf, and strfroml functions

See also

prints formatted output to stdout, a file stream or a buffer
(function)
converts a byte string to a floating point value
(function)