Thread: Problem with sorting an array

  1. #1
    Registered User
    Join Date
    Apr 2002

    Problem with sorting an array

    I'm creating a rpg and I'm having problems with an array sort. the following code is suppossed to sort through a list of skills and if the character already has the skill or if his stats don't allow him to take that skill then it won't be added to the list... but it doesn't seem to be working right. So if someone could help it would be nice.

      int start,end,put=0;
      int x;
      for (x=start;x<=end;x++)
        if ((skills[x]==0)&&(stats_allow_skill(stats,skill_list[x])==true))
    Find_skill_type() finds the start and end position of skills of a certain type from the main skill list.

    stats_allow_skill() passes back true if he can take it or false if he can't

    skills is the characters skill list (which corresponds to the same point in the skill_list array.)
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    You are passing the start and end variables by value, which means the values they get in the function won't be accessible in the for-loop. Use pointers:
    Find_skill_type(type, skill_list, &start, &end);
    void Find_skill_type(int type, int skill_list, int* start, int* end)

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    I just figured out the problem twas something in the function that was calling this one. forgot a -1 *sigh*
    oh and and Find_skill_type() uses passing by reference for start and end so that was okay but thanks for replying though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Problem sorting an array of strings
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 05-07-2008, 09:02 PM
  3. Problem with copying a string into array in a struct
    By JFonseka in forum C Programming
    Replies: 15
    Last Post: 05-04-2008, 05:07 AM
  4. Problem with file and array
    By paok in forum C Programming
    Replies: 5
    Last Post: 05-01-2008, 04:19 AM
  5. 3D array problem
    By rainman39393 in forum C++ Programming
    Replies: 1
    Last Post: 03-15-2008, 06:09 PM