JasBascom said:
thank you unforgiven
is left an object of Allrecords
Yes, so is right.
say: union Allrecords left, right?
You don't need to repeat the union keyword in C++. That's necessary in C,
but not in C++.
I've never come across operators before, what is their purpose in the
great scheme of things?
You use operators all the time. +, -, <, >, ==, whatever are all operators.
C++ has the ability to create your own operators for your own types. What my
code did, was define a 'smaller than' operator for two objects of type
Allrecords. The code I put in the operator function is probably not what you
would want it to do though. You just need to make sure that the function
returns 'true' when 'left' is smaller than 'right' (ie. 'left' should appear
before 'right' in the sort order), and 'false' when 'left' and 'right' are
equivalent or 'right' is smaller.
std::vector<Allrecords> is that to be declared before the operator
function?
No, std::vector<Allrecords> would be a replacement for Allrecords *rec.
vector is a (safer) alternative to an array, but as I said (and John
Harrison too) it's perfectly possible to sort the existing array using
std::sort.
This is the sort function I have, how can i change it so it works in
the manner you suggested.
the union object rec
union Allrecords *rec
is being sorted from a binary file.
The idea behind this sort is to take two lines from the file and
check that they null terminate '\0' because customer_code is 6 arrays
long. Then use strcmp to compare the two, as Newcrecord.customer_code
is declared as type char, use temp to store it while shuffling the
pack around.
As it is it doesn't work.
It's not exactly clear what you're trying to do. What sort algorithm are you
using? It looks a bit like Bubblesort, but it doesn't seem right. Are you
sure you need three nested loops? In any case, you shouldn't be reusing 'i'
in all three loops, because this way it'll have the value 'loop' when it
exits the innermost loop and therefore exits the outer loops as well. What
is 'loop' exactly? Is it the upperbound on rec (it looks like that anyway)?
What exactly is the definition of customercode? char or char* or char[]?
What is the criterea that defines whether to objects of type Allrecords are
equal, smaller or larger than each other? Could you perhaps give the entire
definition of Allrecords as well, including the structs in it, it would help
a lot.