Please help debug for this newbie! Pls

This is a discussion on Please help debug for this newbie! Pls within the C Programming forums, part of the General Programming Boards category; Hi, I am relatively new at C and am a lil stuck on this function. It is meant to sort ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    63

    Question Please help debug for this newbie! Pls

    Hi,
    I am relatively new at C and am a lil stuck on this function. It is meant to sort the array in ascending array w/o creating any integer arrays and chaning the original array.
    Please do help.

    void AscSort(int OrgAry[],
    int* AscAry[])
    {
    /* Local Defintions */
    int i;
    int *pWalk;
    int temp;

    /* Statements */
    for(pWalk = AscAry; pWalk < SIZE; pWalk++)
    {
    for(i = 0; i < SIZE; i++)
    {
    AscAry[i] = OrgAry[i];
    if(*AscAry[i] > *AscAry[i + 1])
    {
    temp = *AscAry[i + 1];
    *AscAry[i + 1] = *AscAry[i];
    *AscAry[i] = temp;
    }
    }
    }
    return;
    }

  2. #2
    Unregistered
    Guest
    I'm a newbie, too, so don't expect too much. If you want to sort an array SIZE, you can only make SIZE - 1 comparisons, because you are using 2 elements for each comparison. Also, I would copy the array first and then sort it. You seem to be combining the two, so that the statement:
    AscAry[i] = OrgAry[i];
    keeps taking you back to square one.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    63
    Thanks whoever it was..
    AscAry is an array of pointers and OrigAry is an array of integers..I don't know if I need to copy the array..but I do know that I need each element in AscAry to point to a corresponding elment in OrigAry..How would I do that??
    Thanks though

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop multiposting. You don't need to post the same question multiple times. The main reason for this, other than the fact that it is annoying, is that your "answers" will be spread all over multiple threads, making it harder for you to get the answe you're looking for.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  2. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  3. newbie here.. pls help me in this program!
    By rothj0hn in forum C Programming
    Replies: 2
    Last Post: 02-01-2006, 09:40 PM
  4. Pls debug my scroll program
    By Raison in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2004, 07:30 PM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2002, 11:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21