Author Topic: _sort() invalid parameters  (Read 2643 times)

SJA

  • Community Member
  • Posts: 17
  • Hero Points: 0
_sort() invalid parameters
« on: May 30, 2013, 02:29:03 pm »
I am writing a macro that has a FOR loop.  Each time through the loop, it performs the following:

_str sorting_array[], counting_array[];

for ( .... )
{
sorting_array._makeempty();
(populate sorting_array[] with about 13,000 string values)
sorting_array._sort();
counting_array._makeempty();
(consolidate sorting_array data into counting_array)
counting_array._sort("D");
(do things with counting_array[])
}

The third time through the loop, on the fifth call to _sort(), I get an "invalid argument" break.  Any suggestions?

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: _sort() invalid parameters
« Reply #1 on: May 30, 2013, 03:02:49 pm »
Maybe one of the 13,000 string values is confusing _sort().
If that's the case, capturing the 5th set of string values and using "divide and conquer" could find specifically which string value confuses _sort() in ceiling(log_2(13,000)) = 14 attempts.

SJA

  • Community Member
  • Posts: 17
  • Hero Points: 0
Re: _sort() invalid parameters
« Reply #2 on: May 30, 2013, 05:14:15 pm »
Thank you, Chrisant.  That pointed me towards the solution.

I was using the split2array() function to parse a line of tab separated values into one_line[ ].
Then I copied each element of one_line[ ] to many_lines[ x ][ ], for x = 0 to 13301.
Then I copied all the values of many_lines[ x ][ y ] to sorting_array[ x ].

It seems clunky, but it allowed me to use split2array() to read lines and sort() to sort columns.

It has been a while since I programmed in SlickC and I forgot there was a difference between an array element with a null string and an unallocated array element.  Most lines of the input file had seven values.  Line #953 had only three values.  Apparently, when the loop handled the fourth column, I managed to allocate most of the elements of sorting_array[ ] from 0 to 13301, with the notable exception of sorting_array[ 952 ].

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: _sort() invalid parameters
« Reply #3 on: May 31, 2013, 04:04:12 am »
Sweet, nice work.  And thanks for posting the outcome, too.   :)