I know I'm being really dumb here, but what's the best way of returning two numbers from a C-function back to the main method?
void main()
{
double firstDouble, secondDouble;
firstDouble = function(&secondDouble);
// etc.
}
double function(double *doubleRef)
{
*doubleRef = 2.0;
return 1.0;
}
There's no way to return more than one value.
The solution is to pass a pointer to a variable into your function, and set the value at that address in the function.
For example:
Code:void main() { double firstDouble, secondDouble; firstDouble = function(&secondDouble); // etc. } double function(double *doubleRef) { *doubleRef = 2.0; return 1.0; }
typedef struct {
double one;
double two;
} DoubleDouble;