Distance calculation implementation
There's nothing wrong with your implementation. There must therefore be something wrong with how you're declaring or populating gp.
Doing it like this:

double gp[4] = {36.987814, -122.107887, 38.989185, -122.116728};
printf("%.6f\n", getDist(gp));


gives the expected answer of 222606.439993