Basically, I have a C function that prints out certain numbers and I also want the function to return 2 values. I have tried this out using struct
but I did not do this correctly and I am not sure how to proceed. I have read other questions and I understand that using a pointer would be better but I am not sure how to.
My C code is as follows:
struct re_val
{
double predict_label;
double prob_estimates;
predict_label = 5.0;
prob_estimates = 8.0;
};
int c_func(const char* dir, double a, double b, double c, double d)
{
double x[] = { a, b, c, d };
printf("x[0].index: %d \n", 1);
printf("x[0].value: %f \n", x[0]);
printf("x[1].index: %d \n", 2);
printf("x[1].value: %f \n", x[1]);
printf("x[2].index: %d \n", 3);
printf("x[2].value: %f \n", x[2]);
printf("x[3].index: %d \n", 4);
printf("x[3].value: %f \n", x[3]);
return re_val;
}
Ultimately, I would like to call only one function that is able to print out the array and return predict_label
and prob_estimates
.
I am actually calling this function in python via ctypes and my python function is included bellow.
calling_function = ctypes.CDLL("/home/ruven/Documents/Sonar/C interface/Interface.so")
calling_function.c_func.argtypes = [ctypes.c_char_p, ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double]
calling_function.c_func.restype = ctypes.c_double
y = calling_function.c_func("hello",1.1, 2.2, 3.1, 4.2)
print y