Thread: Help Needed!!!

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    Help Needed!!!

    hi, hope someone can shed some light on this for me, I'm a bit stumped at the moment.

    Writing a prog to read records from a binary file into memory using malloc() thenh sort them using q sort.

    record structures are as follows.......

    struct ir_record {
    char rec_type;
    char cust_code[6];
    char p_num[7];
    char ir_quantity[5];
    };

    struct d_record {
    char rec_type;
    char cust_code[6];
    };

    struct c_record {
    char rec_type;
    char cust_code[6];
    char cust_name[21];
    char cust_addr[61];
    char cust_bal[10];
    char limit[8];
    };

    union records {
    struct ir_record issue_receipt;
    struct d_record deletion;
    struct c_record creation;
    };

    the records must be sorted first by cust_code and then any with the same code must be sorted so that the c_record comes last.

    can anyone show me how to write the 2 comparison functions needed to perfrom this sort????



    Colin

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    x = strcmp( s1.cust_code, s2.cust_code )
    if ( x < 0 )
    {
       ...s1 goes before s2...
    }
    else
    if ( x > 0 )
    {
       ...s2 goes before s1...
    }
    else
    {
       ... equal, so do whatever your other comparison is...
    }
    I'm not sure what you mean by "c_record comes last" so you'll have to figure out your other comparison on your own.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    16
    Hi, I can send you my code for this, if you can help me with P1 Validate, fellow Computeach student!

    My code works fine except for finding the missing name in the secret td.dat used by Computeach.
    I use fgets to read the records and I think this is where I'm going wrong, my code is ok unless the name field (or address) is completely missing ( ie record is 20 or 60 chars too short ), then it all goes t*ts up and starts reading the next record!

    You scratch my back etc!

    My P2 works fine!

    cheers

    foffo
    'C that?... I felt nowt' - The Original Foffo Spearjig and his hard dog. The Tube TV show, sometime in the 80's

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  4. Releasing a program - what is needed? A few Q's
    By ulillillia in forum Tech Board
    Replies: 9
    Last Post: 04-28-2007, 12:18 AM
  5. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM