Solved

How does sprintf work ?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

785 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