Ok. I'm not entirely sure what you mean by "your code doesn't sort my rows, just rearrange it". Do you mean that it rearranges the rows internally, or with respect to each other? If the latter, how does this differ from sorting? Do you just mean it's not sorting them like you want?
Just to see if we can find some common ground, let me tell you about my experience trying to run the code you posted (without modification).
The first error I got was on the
ReadLine call:
"Array argument too small (100 bytes). Argument must contain at least 101 bytes (101 elements)."This was remedied by changing the second malloc from this:
*(StringTemp + i) = (char *) malloc(row_length * sizeof(char) ); //100*1to this:
*(StringTemp + i) = (char *) malloc((row_length + 1) * sizeof(char) ); //101*1The second error I received was:
"Array argument too small (101 bytes). Argument must contain at least 2128 bytes (2128 elements)."on the line:
qsort ( *StringTemp, rows, 112, DataCheck); //correctI then tried commenting this line out and using the line:
qsort ( *StringTemp, rows, (row_length * sizeof(char)), DataCheck); //incorrectand received the error:
"Array argument too small (101 bytes). Argument must contain at least 1900 bytes (1900 elements)."The changes I then made to solve this problem are what I described in my original post.
I changed the first malloc call from this:
StringTemp = (char **) malloc(rows * row_length* sizeof(char)); //19*100*1to this:
StringTemp = (char **) malloc(rows * sizeof(char *));I changed the qsort call from this:
qsort ( *StringTemp, rows, 112, DataCheck); //correctto this:
qsort (StringTemp, rows, sizeof(char *), DataCheck);I changed the DataCheck function from taking (char *) parameters to taking (char **) parameters (because of the change to the qsort call). This changed this:
char *Arg1 = (char *)arg1; char *Arg2 = (char *)arg2;to this:
const char *Arg1 = *(const char **)arg1;
const char *Arg2 = *(const char **)arg2;At this point, I created a dummy data file to read in to test the changes. In my tests, the rows are sorted without issue. I then changed your DataCheck function to the function I posted in my original post (just calling strcmp). The results were the same. The reason for this is that the date string is presented in order of decreasing significance (year, month, day, hour, minute, etc.). This means that a textual sort will do the same thing as the complicated comparison you were doing in DataCheck.
I am attaching a project which contains my code and yours so you can test it for yourself.
It is possible you have some other code that is causing the problem you originally posted about (the 100 vs 112 problem) but I could never reproduce that issue, and I can't think of any reason that it would happen. It is possible that the issue you are seeing is limited to a specific version of CVI; which version are you using?
At any rate, try the project I attached and let me know how it goes.
Regards,
-alex