While i am working ,somewhere inside the code i saw the following staements.
I am getting confused by the format specifier in sprintf
d_number = strtol( tmp_buf , (char **)NULL, 16);
memset( tmp_buf , ' ' , sizeof( tmp_buf ) );
sprintf( tmp_buf , "%0.*d" , (int)sizeof( dec_number ) , d_number );
could anybody explain please?
Format specifiers define the type of data to be printed on standard output. You need to use format specifiers whether you're printing formatted output with printf() or accepting input with scanf() .
%s refers to a string %d refers to an integer %c refers to a character. Therefore: %s%d%s%c\n prints the string "The first character in sting ", %d prints i, %s prints " is ", and %c prints str[0].
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.
There are mostly six types of format specifiers that are available in C.
.*
means the precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. (d_number)
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With