Solved

How does sprintf work ?

Posted on 2014-02-06
3
251 Views
Last Modified: 2014-02-06
sprintf(iso8601_buf,"%4.4d-%2.2d-%2.2d",usYear,usMon,usDay);

Open in new window


usYear, usMon, and usDay are unsigned short.

Please explain the second argument of above sprintf ( ) in detail.
0
Comment
Question by:naseeam
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 350 total points
ID: 39840070
The format is like

%[precision].[max_len]d

(you could also think of that as '%[min_len].[max_len]d') with the above formatting an output string according to the ISO 1806 format (YYYY-MM-DD) that you specified in your other Q, thus ensuring that the three values that form the date are arranged exactly as

[4 digits year]-[2 digits month]-[2 digits day]

with the hyphens in betwee.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39840072
Ooops, forgot - see also the detaild description at http://en.cppreference.com/w/c/io/fprintf
0
 

Author Closing Comment

by:naseeam
ID: 39840199
extremely fast response time.  Thank you!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now