Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C format specifier

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?

like image 789
Vijay Avatar asked Feb 08 '10 11:02

Vijay


People also ask

What is format specifier in C?

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() .

What is %d %s in C?

%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].

What is %d and & in C?

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.

How many format specifiers are there in C?

There are mostly six types of format specifiers that are available in C.


1 Answers

.* 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/

like image 137
stacker Avatar answered Sep 30 '22 01:09

stacker