I would like to sort an array alphabetically that looks like this:
I have tried various methods, but still no way. it crashes, and no idea yet why. Would you have some tips to start with this issue?
Since that I am not so much expert, the code is aimed at being simple (to read/understand) and doing the job.
thx, Regards
/* note: datalist[...] is basically the ouput from a sort of ls (dir
read) that it unsorted. So that: datalist[0] is ".." datalist[1] is
"file2.c" datalist[2] is "file34.c" and so on.*/
char datalist[500][2024] ;
void sortData(int aoptiondt) { ///////////////////////////LOCAL
DECLARATIONS///////// int MAX = 500 ; int current; int walker;
int smallestIndex; char* temp;
///////////////////////////DEFINITIONS//////////////////
for (current = 0; current < MAX - 1; current++)
{
smallestIndex = current;
for (walker = current; walker < MAX ; walker ++)
{
if (strcmp(datalist[walker], datalist[smallestIndex]) < 0)
smallestIndex = walker;
} //for walker
//Swap to position smallest at what is the current position
strncpy( temp , datalist[current] , PATH_MAX);
strncpy( datalist[current] , datalist[smallestIndex] , PATH_MAX);
strncpy( datalist[smallestIndex] , temp, PATH_MAX);
} //for current }
return; }
//blabla
int main() {
}
mainand an arraydatalist, nothing more than that. There is no trace of your various methods.