Solved

How does sprintf work ?

Posted on 2014-02-06
3
283 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 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