Velocity Reviews > error problems

# error problems

Bill Cunningham
Guest
Posts: n/a

 02-19-2011
James Waldby wrote:
> On Fri, 18 Feb 2011 17:19:59 -0500, Bill Cunningham wrote:
>> osmium wrote:

> ...
>>>>>> My intent was to use a 6 digit format such as 021711. That's
>>>>>> why I used an array of 6.
>>>>>
>>>>> Don't use digits, use numbers. 17 is a number, it has two
>>>>> digits, 1 and 7. It will be much easier to do your computation
>>>>> (later) if you use numbers instead of digits. You, Bill, will
>>>>> have to provide
>>>>> a carry mechanism
>>>>
>>>> A carry mechanism?
>>>
>>> 17+5 = 22, the left digit changes from 1 to 2 because of a carry.
>>> You said earlier you wanted to compute. Addition is about the
>>> simplest computation there is. If you treat the 7 as an element of
>>> an array, you must provide a carry if you want to add to the 7.

>>
>> I'm not quite sure I understand. I will give this some thought
>> though.

>
> Dates, times, or dates+times can be represented several different
> ways in a computer. Choice of representation affects what is easy
> to do with them.

Ok I think I'm beginning to see. I was just going to use and ansi or iso
c sort function to sort. I'm just trying to get a struct to store in and
pull from right now.

> With the date representation you mentioned (six characters or digits
> for mmddyy) it is easy to do input and output but less easy to do
> arithmetic (such as the amount of time between two dates, or what
> day is 180 days after a date). To do such arithmetic, you may need
> to compute carries; for example, "021811" + 14 days = "030311".
>
> With date represented in an object of type time_t as defined by
> the <time.h> header file it is easy to do date arithmetic (the
> time_t type typically is like a 32-bit or 64-bit integer type)
> and using routines mentioned in next paragraph it isn't difficult
> to do input and output.
>
> See <http://en.wikipedia.org/wiki/Time_t> for a time_t example.
> Also read man pages for routines declared in <time.h>: clock(),
> time(), difftime(), mktime(), strftime(), strptime(), gmtime(),
> asctime(), ctime(), and reentrant versions of same. These
> address the time-handling problems that people find it useful
> to address, and using them may help avoid errors.
>
>>> One of the better answers you were given last week was to use the
>>> facilities in <time.h> but you chose to ignore that suggestion, for
>>> reasons known only to you, and go your own way.

>>
>> If I wanted to add yesterdays data today, would time.h be a very
>> good way to go? I keep track of friday's data. Sometimes I add
>> it on saturdays. Does this make sense?

> ...

osmium
Guest
Posts: n/a

 02-19-2011
"Bill Cunningham" wrote:

>> One of the better answers you were given last week was to use the
>> facilities in <time.h> but you chose to ignore that suggestion, for
>> reasons known only to you, and go your own way.

>
> If I wanted to add yesterdays data today, would time.h be a very good
> way to go? I keep track of friday's data. Sometimes I add it on saturdays.
> Does this make sense?

Yes, you can handle that. You can record the current date by using the time
function or you can fabricate a different date using the mktime function.
Sorting will be relatively straightforward too. I suggest you write a
little stand alone program using those two functions (and whatever is
necessary to prove that it works) to see what you might be in for. You will
almost surely need some material to supplement K&R. Writing a separate
program will allow you to FOCUS.

Ike Naar
Guest
Posts: n/a

 02-19-2011
On 2011-02-18, James Waldby <(E-Mail Removed)> wrote:
> With the date representation you mentioned (six characters or digits
> for mmddyy) it is easy to do input and output but less easy to do
> arithmetic (such as the amount of time between two dates, or what
> day is 180 days after a date). To do such arithmetic, you may need
> to compute carries; for example, "021811" + 14 days = "030311".

Do you live in a place where 11 is a leap year?

James Waldby
Guest
Posts: n/a

 02-19-2011
On Sat, 19 Feb 2011 10:39:51 +0000, Ike Naar wrote:

> On 2011-02-18, James Waldby <(E-Mail Removed)> wrote:
>> With the date representation you mentioned (six characters or digits
>> for mmddyy) it is easy to do input and output but less easy to do
>> arithmetic (such as the amount of time between two dates, or what day
>> is 180 days after a date). To do such arithmetic, you may need to
>> compute carries; for example, "021811" + 14 days = "030311".

>
> Do you live in a place where 11 is a leap year?

No, but if you misread the calendar properly, the
above works out.

--
jiw

Coos Haak
Guest
Posts: n/a

 02-19-2011
Op Sat, 19 Feb 2011 22:19:42 +0000 (UTC) schreef James Waldby:

> On Sat, 19 Feb 2011 10:39:51 +0000, Ike Naar wrote:
>
>> On 2011-02-18, James Waldby <(E-Mail Removed)> wrote:
>>> With the date representation you mentioned (six characters or digits
>>> for mmddyy) it is easy to do input and output but less easy to do
>>> arithmetic (such as the amount of time between two dates, or what day
>>> is 180 days after a date). To do such arithmetic, you may need to
>>> compute carries; for example, "021811" + 14 days = "030311".

>>
>> Do you live in a place where 11 is a leap year?

>
> No, but if you misread the calendar properly, the
> above works out.

Only when it's midnight in Greenwich, evening in Europe and Africa and
morning in America

--
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html

Bill Cunningham
Guest
Posts: n/a

 02-20-2011
Ike Naar wrote:

> Do you live in a place where 11 is a leap year?

Me ? No. But I never considered that. I wanted easy IO of dates. Now I
have others to thank for telling (or reminding) me of time.h though I never
really knew its power. I will probably use mktime.

B

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post stevenruiz@gmail.com C++ 2 02-13-2007 09:04 PM bazzer ASP .Net 1 03-24-2006 04:20 PM bazzer ASP .Net 0 03-24-2006 02:22 PM Bun Mui Computer Support 0 06-18-2004 11:29 AM manish C++ 1 04-02-2004 12:33 PM