Solved

How does sprintf work ?

Posted on 2014-02-06
3
262 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 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

18 Experts available now in Live!

Get 1:1 Help Now