?
Danke für den Tipp mit der Struktur,
habs hinbekommen.
Hier ein kleiner Besispielcode aus dem Netz
#include <stdio.h>
#include <stdlib.h>
typedef int (*compfn)(const void*, const void*);
struct coord { double X;
double Y;
double Z;
long int num;
};
struct coord array[10] = { { 10.23,10.23,10.23,10 },
{ 5.23,5.23,5.23,5 },
{ 3.23,3.23,3.23,3 },
{ 4.23,4.23,4.23,4 },
{ 2.23,2.23,2.23,2 },
{ 6.23,6.23,6.23,6 },
{ 9.23,9.23,9.23,9 },
{ 8.23,8.23,8.23,8 },
{ 7.23,7.23,7.23,7 },
{ 1.23,1.23,1.23,1 } };
void printarray(void);
int compare(struct coord *, struct coord *);
int main(void)
{
printf("List before sorting:\n");
printarray();
qsort(array,10,sizeof(struct coord),(compfn)compare );
printf("\nList after sorting:\n");
printarray();
}
int compare(struct coord *elem1, struct coord *elem2)
{
if ( elem1->Z < elem2->Z)
return -1;
else if (elem1->Z > elem2->Z)
return 1;
else
return 0;
}
void printarray(void)
{
int i;
for (i = 0; i < 10; i++)
printf("%d: Punkt X: %f Y: %f Z: %f Index:%ld\n",
i+1, array[i].X,array[i].Y,array[i].Z, array[i].num);
}