There is an array of structures. Wrote the swap function

swap(Struc *x1, Struc *x2) { Struc *temp; temp = x1; x1 = x2; x2 = temp; } 

I am trying to call it swap(&mass[i], &mass[i+1]) but I ran into the problem that nothing really changes places in the array. What am I doing wrong?

  • assign values, not addresses - Igor
  • Could you write a sample code? - Gilbert

1 answer 1

You swap pointers themselves, but not values. Try this:

 swap(Struc *x1, Struc *x2) { Struc temp; temp = *x1; *x1 = *x2; *x2 = temp; }