Sorry if this question seem newbie, I've started learn C a few days ago.
I have a function(get_taken_values) that should take a string(char[81) as input and return two values: a int and a int[9].
As I saw here, it's not possible to return multiple values, so I had to use a struct.
Here's what I have:
#include <stdio.h>
#include <stdlib.h>
#define max_size 9
#define max_input 81
struct result {
int position;
int *taken;
};
struct result get_result(int pos, int take[]){
struct result res;
res.position = pos;
res.taken = take;
return res;
}
struct result get_taken_values(char string_arg[max_input]){
int position = 0;
int* chosen = calloc(max_size, sizeof(int)); //suggestion from a previous question
int someotherarray[9] = {1,2,3,4,5,6,7,8,9}; // fictional
int i;
for (i = 0; i < max_size; i ++) {
chosen[i] = someotherarray[i];
}
struct result res = struct result(position, chosen);
return res; // I to return int and int[9]: eg: 0,{1,2,3,4,5,6,7,8,9}
}
But I'm getting:
ex16.c: In function 'get_taken_values':
ex16.c:127:22: error: expected expression before 'struct'
struct result res = struct result(position, chosen);
^
I tried cutting the get_result, and creating the struct in get_taken_values:
// inside get_taken_values
struct result res;
res.position = position;
res.taken = chosen;
return res;
But it raises this:
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
I intend to pass the return value from get_taken_values to Python and use it there.
What's the correct way of doing this?