Thread: assigning two array of two stractures

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    11

    assigning two array of two stractures

    I need help to assign two array of stractures to each other?!!

    Many Thanks

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    post your code - we cannot read your mind, so show us what you have already.

    ~/

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    11
    Thanks for you reply, actually I need to use qsort() function. I got a global array of structure as follows:

    RECORD record[MAX_NO_ITEM]; //global- kept without change

    and I have a function that I need to declare another array of structures to send it as an arrgument to qsort() as follows:

    void sort_record()

    ({

    RECORD sorted_rec[MAX_NO_ITEM];// here is a new declaration of array of strutures

    // here I need to assign record to sort_record ?????
    //It is silly to try: sorted_rec[] = record[]


    qsort(sorted_rec, no_of_items, sizeof(RECORD), compare_stock);

    //dispaly the sorted items by using sorted_rec
    })

    the reason for declaring a new array of stracture "sorted_rec" , as you may getting the idea, is to keep the content of "record" un changed.
    Code:
    hello

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use a for loop and do
    sorted_rec[i] = record[i];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    11
    Can I use pointers to do the job.

    Thanks

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What do you mean - "use pointers"
    It will be a lot quicker to sort an array of pointers than sort an array of records, if that's what you mean.

    If you mean rewrite the loop using pointer notation, then no it wont be any quicker.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modify an single passed array element
    By swgh in forum C Programming
    Replies: 3
    Last Post: 08-04-2007, 08:58 AM
  2. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. Assigning the value of a const array to a normal array
    By Accident Prone in forum C++ Programming
    Replies: 6
    Last Post: 08-11-2003, 10:40 PM
  5. assigning values in file to an array
    By divinyl in forum C++ Programming
    Replies: 9
    Last Post: 07-29-2003, 08:33 AM