You need a struct. Create the struct and fill in its x, y, z and then return it.
There are also lots of unnecessary variables in your functions.
Warnings:
Code:
Warning 1 warning C4101: 'y2' : unreferenced local variable 11
Warning 2 warning C4101: 'x2' : unreferenced local variable 11
Warning 3 warning C4101: 'y1' : unreferenced local variable 11
Warning 4 warning C4101: 'lat' : unreferenced local variable 11
Warning 5 warning C4101: 'z2' : unreferenced local variable 11
Warning 6 warning C4101: 'rho' : unreferenced local variable 11
Warning 7 warning C4101: 'lengtha' : unreferenced local variable 11
Warning 8 warning C4101: 'x1' : unreferenced local variable 11
Warning 9 warning C4101: 'lengthb' : unreferenced local variable 11
Warning 10 warning C4101: 'theta' : unreferenced local variable 11
Warning 11 warning C4101: 'z1' : unreferenced local variable 11
Warning 12 warning C4101: 'y2' : unreferenced local variable 35
Warning 13 warning C4101: 'x2' : unreferenced local variable 35
Warning 14 warning C4101: 'z2' : unreferenced local variable 35
Warning 17 warning C6001: Using uninitialized memory 'lat2': Lines: 11, 12, 14, 16, 17, 19, 20 20
Warning 18 warning C4700: uninitialized local variable 'lat2' used 20
Warning 19 warning C4700: uninitialized local variable 'ptr2' used 24
I also removed some variables that are unnecessary:
Code:
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
double gc_distance(double x);
double rectangle(double *str);
int main(void)
{
double lat1,*lat[4], long1, lat2, long2, x1, y1, z1, x2, y2, z2, theta, rho, lengtha, lengthb;
double retrive[4];
//double *ptr1;
double ptr2[4];
//ptr1=retrive;
printf("enter latitude and longitude of the first city\n");
scanf("%f%f",&lat1,&long1);
retrive[1]=lat1;
retrive[2]=lat2;
rectangle(retrive);
printf("\n\n%.2f %.2f %.2f\n",ptr2[1],ptr2[2],ptr2[3]);
printf("enter latitude and longitude of the second city\n");
scanf("%f%f",&lat2,&long2);
return 0;
}
double rectangle(double *str)
{
double phi, theta, rho, x1, y1, z1, x2, y2, z2;
double test[4];
//double *ptr;
//ptr = test;
phi= (90 - str[1])*(PI/180);
theta=(360 - str[2])*(PI/180);
rho= 3960;
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
printf("%.2f %.2f %.2f\n\n", x1,y1,z1);
test[1] = x1;
test[2] = y1;
test[3] = z1;
printf("%.2f %.2f %.2f\n\n", str[1],str[2],str[3]);
//return (*ptr);
return 0.0;
}