C Language : snprintf usage

<stdio.h> # Include
# include <stdlib.h>
/ *
int snprintf (char * restrict buf, size_t N, const char * restrict Format, ...);
Function Description: copy from the source string up to n-1 characters in the target string, and then later add a 0. Therefore, if the size of the target string is n
                 , it will not overflow.
Function return values: If successful, returns the length of the string to be written, if an error is returned negative.
* /
int main () { char str [ 10 ] = { 0 ,}; snprintf ( str , sizeof ( str ), "% s" , "0,123,456,789,012,345,678" ); printf ( "str =% s ​​\ N " , str ) ; return 0 ; }


Learn More :