Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: King - Chapter 5 date.c |
| Date | 2011-12-21 03:55 -0800 |
| Organization | None to speak of |
| Message-ID | <lnbor22l6z.fsf@nuthaus.mib.org> (permalink) |
| References | <a77e63e8-c922-4aa0-9fed-2bdde8328d16@18g2000prn.googlegroups.com> <slrnjf25ju.2n2l.usenet-nospam@guild.seebs.net> <163e5337-d75d-49b3-9953-50f42e14dc6a@a31g2000pre.googlegroups.com> |
flebber <flebber.crue@gmail.com> writes:
> On Dec 21, 10:13 am, Seebs <usenet-nos...@seebs.net> wrote:
[...]
>> You told the user to enter a *4-digit* year (good move) and now
>> you're going to discard the century entered and use 20?
>
> The book states that the 20%.2d has to be used as otherwise a year
> such as 2005 would be printed as 205.
I suspect you've misunderstood what the book says.
If the year value is a 2-digit year restricted to the years 2000-2099,
then printing it with "20%.2d" should work. If you print it with
"20%d", it won't print a leading 0 for values less than 10, so a year
entered as 5 will print as "205" rather than the correct "2005".
In some contexts, it's common to represent as year as the number of
years since 1900 (this is how the tm_year member of struct tm, defined
in <time.h>, works). If you were using that representation, you
wouldn't want to prepend either "19" or "20" to the year; you'd want to
add 1900 to it.
But as Seebs says, your prompt is:
printf("Enter the date mm/dd/yyyy: ");
which asks for a 4-digit year. The user is going to enter "2005", not
"05" or "5".
Perhaps the book intends the prompt to be:
printf("Enter the date mm/dd/yy: ");
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
King - Chapter 5 date.c flebber <flebber.crue@gmail.com> - 2011-12-20 14:50 -0800
Re: King - Chapter 5 date.c Seebs <usenet-nospam@seebs.net> - 2011-12-20 23:13 +0000
Re: King - Chapter 5 date.c flebber <flebber.crue@gmail.com> - 2011-12-20 20:43 -0800
Re: King - Chapter 5 date.c Geoff <geoff@invalid.invalid> - 2011-12-20 22:47 -0800
Re: King - Chapter 5 date.c Seebs <usenet-nospam@seebs.net> - 2011-12-21 08:00 +0000
Re: King - Chapter 5 date.c Geoff <geoff@invalid.invalid> - 2011-12-21 00:22 -0800
Re: King - Chapter 5 date.c Keith Thompson <kst-u@mib.org> - 2011-12-21 03:55 -0800
Re: King - Chapter 5 date.c James Kuyper <jameskuyper@verizon.net> - 2011-12-21 08:22 -0500
Re: King - Chapter 5 date.c flebber <flebber.crue@gmail.com> - 2011-12-20 20:50 -0800
Re: King - Chapter 5 date.c Geoff <geoff@invalid.invalid> - 2011-12-20 22:45 -0800
Re: King - Chapter 5 date.c André Gillibert <MetaEntropy.removeThis@gmail.com> - 2011-12-21 11:35 +0100
Re: King - Chapter 5 date.c Geoff <geoff@invalid.invalid> - 2011-12-21 03:57 -0800
Re: King - Chapter 5 date.c Seebs <usenet-nospam@seebs.net> - 2011-12-21 19:12 +0000
Re: King - Chapter 5 date.c "BartC" <bc@freeuk.com> - 2011-12-21 22:17 +0000
Re: King - Chapter 5 date.c James Kuyper <jameskuyper@verizon.net> - 2011-12-21 18:07 -0500
Re: King - Chapter 5 date.c superpollo <superpollo@tznvy.pbz> - 2011-12-21 14:44 +0100
csiph-web