ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'll have to leave it up to Gtk to post a brilliant solution. However, rmartine came across basically the middle ground between individual variables and structures: arrays.
I'd provide some code, but it's 12:47 AM in Houston, and I need to get to bed. So, I'll leave you with some suggestions on what you should try doing to improve the program.
1) Look at your data types. How many floats do you have with different names? Do you think it might be possible to consolidate at least some of them into logical groups using arrays?
2) Look at your read_GPS function. Is it necessary to call it four times? Would it be possible to consolidate all four user input requests into one function call? There's a way to do it and pass a total of 5 arguments using only arrays.
I know, I probably sound like a TA, but like I said, it's... ugh.... 12:58 now. Gotta go.
Originally posted by Randall right
forgot that other code thingie
let's try that again
Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define RHO 6367
#define PI 3.141592654
void read_GPS(float *,float *,float *,char *);
float calc_3DCoord(float *, float *);
int main(void)
{
printf("Please enter in longitudinal co-ordinates for start point:\n");
read_GPS(°_long_1,&min_long_1,&sec_long_1,s2);
dec_deg_2 = convert_DD(°_long_1,&min_long_1,&sec_long_1);
rad_long_1 = calc_SphereCoord_long(s2, &dec_deg_2);
theta_long_1 = deg2rad(&rad_long_1);
calc_3DCoord(&phi_lat_1, &theta_long_1);
What are you doing with the zero return value?
printf("%c", getchar());
return(0);
}
void read_GPS(float *degrees,float *minutes,float *seconds,char *direction)
{
scanf("%f%f%f%s", degrees, minutes, seconds, direction);
return;
return statement is redundant
}
float calc_3DCoord(float *phi, float *theta)
{
float temp_1, temp_2, temp_3;
temp_1 = (RHO * (sin(*phi)) * (cos(*theta)));
temp_2 = (RHO * (sin(*phi)) * (sin(*theta)));
temp_3 = (RHO * (cos(*phi)));
printf("The cartesian co-ordinates are: %f %f %f\n", temp_1, temp_2, temp_3);
return(0);
Why are you returning a zero integer here?
Maybe this function should return void.
}
Note: You can call a user defined function from another user defined function. For example: convert_DD could call calc_SphereCoord and pass the dec_deg_1 variable. I'm not so sure I want to go through your whole code because it is too unwieldly with all the variables. That's why the designers of the language invented structures and arrays.
i know i have to clean it up
and it's really messy right now
i just wanted to get it working , passing all the information back and forth and that the result of the calculation is correct. if i accomplish that i can clean it up, remove those unescessary printf statements and consolidate some functions and variables.
i'd really like to thank you guys for your input and patience. it was most invaluable. i suppose eventually i'll learn the art of producing aesthetically pleasing as well as functional code. for now i'm just trying to get it to work.
It's getting too hard to read. I suppose that if I had the written requirements than it would be possible to read. I see some of the logic, but it's time to use structures and arrays. Yet if you are almost done, than all I can reiterate some ideas:
In this example, 'myvalue' will be updated in main, because 'SomeFunction' is going to return a copy of a result.
On the other hand, if you want any user defined variables updated in main, and you have more than one, than you can't return them all with the return statement (unless you use a structure) so you will have to use pointers.
Yet in another case, you don't need 'value2' to be updated in main. So you don't have to pass the argument by reference, you can instead pass the argument by value (a copy of it).
i just thought i'd let you guys know, i got it to work, i eneded up calling functions within a function, that seemed to work well enough. i'm now in the process of cleaning up and commenting the code.
i can't thank you guys enough for all the valuable sugestions you gave.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.