So I have an Array of Structs with Months and Days on it, and I want to sort it so the first struct will hold the day 1 of the month 1, the second the day 2 of the mont 1 and so on.
I am trying to do this by storing the correct array in a temporal array and then replacing them.
My problem is, to do the following, the only algorithm I could made crashes my prompt and gives me a segmetation fault. By now i'm confused enough not to know if my logic is wrong or i'm doing it in a too complex way for the program to work.
Here is the function with my cod
void sortData(struct StructData data[], int size){
int i=0,x=0,z=0,v_day=0,v2_day=0;
struct StructData temp[sz];
for (i=0;i!=12;i++){
for (x=0;x!=12;x++){
if (data[x].month == i+1){
for (v=0;v!=31;v++){
for(v2=0;v2!=31;v2++){
if (data[v2].day == v+1){
temporal[z] = data[v2];
z=z+1;
}
}
}
}
}
}
i=0;
for (i=0;i!=size;i++){
data[i] = temporal[i];
}
}
There is probably a better way to do this, I just don't see it.