>>> Part 1 of 2...
-=> Quoting Cliff Rhodes to Paul Druggitt <=-
PD> This if(....) checks each byte for equality, which doesn't quite
PD>solve my problem, which is I wish see which is the lowest value.
CR>
CR> Yep, I just wanted to show you how to do that. I figured you might get
CR> some ideas from that and go from there.
I got plenty of ideas, but couldn't quite grasp the 'mechanics' of
if (*(int *)a > *(int *)b).
PD> 1) How can I check properly which is REALLY the lowest value?
PD> whether it be int, long, double, string etc.....
CR>
CR> There are a number of alternatives.......
CR> static int Icmp(const void *a, const void *b)
CR> {
CR> /* Routine to compare two ints pointed to by a and b */
CR> if(*(int *)a > *(int *)b)
CR> return 1;
CR> else if(*(int *)a < *(int *)b)
CR> return -1;
CR> return 0;
CR> }
Yes, I understand that part now.
PD> 3) Is there an easier way to add records to a file, sorted in the
PD> order I specify(date order, alphabetic order etc...),
CR>
CR> If you change the order, you will in effect have to rewrite the entire
CR> file.
Yes I understand that. What I should have said was that the file will
always be sorted in the same order when adding or "inserting" records.
CR>
CR> Can you fit your entire data file into memory?
No. I envisage the file may eventually become far too large to fit into
the 64K memory available.
CR> Paul, you are giving me a moving target here! First you just wanted to
CR> compare members in different size records, now you want to do a
CR> sorting routine.
I thought that I would be able to work out the rest of it if someone
gave me a start in the right direction.
CR> Why don't you write a message spelling out exactly what you are trying
CR> to accomplish--the big picture. I think there is probably a much
CR> easier way to tackle this design,
I am sure there must be :)
I am trying to write a home accounts program which displays a statement
of the account in date order, regardless of when an entry is made.
Date Type Description Debit Credit Balance
---------------------------------------------------------------------
21/03/97 DD Mortgage 300.00 -300.00
25/03/97 DD Water rates 100.00 -400.00
28/03/97 DD Council Tax 50.00 -450.00
These Direct Debits are updated each time the program is run (if
today's date says they are due).
If today's date is 30/03/97 (30th March in UK format), and the last
time the program was run it was 15/03/97, the above entries will be
added to the file automatically.
On 24/03/97 I bought petrol with a cheque. I want to add this
transaction to the end of the file, to save rewriting the whole file,
but to display in date order, by using prev record, next record
markers.
This I have managed to do, but the method I have used is specific to
this type of structure. Elsewhere in the program I have different
structures for other reports, eg standing orders which keeps a record
of how many payments are still left etc etc, stored alphabetically.
I was trying to write a single function that would add records of
>>> Continued to next message...
--- Blue Wave/Max v2.30 [NR]
---------------
* Origin: The Cavern BBS, Manchester, UK +44-61-796-1770 (2:250/102.0)
|