By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

Reg: Program to get the output as 05 for the same input but not as 5

P: 58
Hi

Can anyone give me a code regarding this. If I give input as 05 I should get the same (05)output but not just 5

output should be like
input: 05
output: 05

not like this
input: 05
output: 5



Thanks in advance
Nov 17 '08 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
You don't say whether you are using C or C++.

For C++, research cout.fill().
Nov 17 '08 #2

Expert 10K+
P: 11,448
... and for C look at the "%02d" format string.

kind regards,

Jos
Nov 17 '08 #3

P: 58
Thank you very much...Now I am getting the output...but not the required one..
In a same input if at all I need to give values like 05, 005, 5, 0005 now if I am giving "%02d" then the output I got is 05, 05, 5, 05.
So I changed to "%03d" and now I am getting 005, 005, 5, 005 but not as same as the input values.
I need the output to be as same as input because I am using lots of data(11350)at a time which has any of the above values
Sorry for not mentioning the Language...I am writing program in C lang....

Regards
Siva
Nov 18 '08 #4

Expert 10K+
P: 11,448
If any number of zeros can be prepended to your number(s) then a simple "%02d"
format string won't help you. Better leave the input as strings (char*) and copy
them verbatim to the output.

kind regards,

Jos
Nov 18 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.