This shows you the differences between two versions of the page.
c:stdio.h:sprintf [2013/01/22 22:02] |
c:stdio.h:sprintf [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== sprintf ====== | ||
+ | <code c> | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | int sprintf(char *str, const char *format, ...); | ||
+ | </code> | ||
+ | Like fprintf, but output written into string s, which must be large enough to hold the output, rather than to a stream. Output is NUL-terminated. Returns length (excluding the terminating NUL). | ||
+ | |||
+ | <code c> | ||
+ | /* | ||
+ | * sprintf example code | ||
+ | * http://code-reference.com/c/stdio.h/sprintf | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | |||
+ | int main( void ) { | ||
+ | |||
+ | char string[11]; | ||
+ | int integer_variable = 42; | ||
+ | |||
+ | sprintf( string, "%d", integer_variable ); | ||
+ | printf("%s\n",string); | ||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||