struct numz
{
int num;
};
typedef struct numz_ numz;
int main()
{
int num_elements = 10;
numz* myStruct_a = smalloc(sizeof(int)*num_elements;
for (n = 0; n < num_elements; n++)
myStruct_a->num[n] = n;
funct(myStruct_a);
return 0;
}
numz *funct(numz *myStruct_a)
{
int num_elements = 10;
numz* myStruct_a_cpy = smalloc(sizeof(int)*num_elements;
for (n = 0; n < num_elements; n++)
{
myStruct_a_cpy->num[n] = myStruct_a->num[n];
}
//PSEUDO CODE
//REARRANGE THE ELEMENTS IN myStruct_a_cpy
return myStruct_a_cpy;
}
Why is myStruct_a_cpy not rearranged?
why are you initializing
myStruct_a_cpywithsmalloc(sizeof(int)*num_elements)? shouldn’t it besizeof(myStruct)?Also, why not just use qsort?
int compare(const void * a, const void * b)
{
myStruct * struct_a = (myStruct*) a;
myStruct * struct_b = (myStruct*) b;
// compare the contents of the two structs,
// return -1 if a < b, 1 if a > b, and 0 otherwise.
}
myStruct *funct(myStruct *myStruct_a)