Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How does sprintf work ?

Posted on 2014-02-06
3
278 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
 
LVL 1

Author Closing Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add values of each row in an array 3 63
Why isn't object file created? 6 68
HTTPSendRequest with WinINet delays on first call 11 30
Android development question 2 53
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

809 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