How can i make Alt.1 to work as intended by passing a pointer of an array and get the requested reference of an array in Alt.1 ?
struct mystruct
{
int id1;
int id2;
};
const struct mystruct local_struct[] = {
{0, 55},
{1, 66},
};
// Alt.1 i like to make this work (not working)
int get_reference_1(const struct mystruct *s){
s = local_struct;
return 0;
}
// Alt.2 works perfect but i like to use the return as status as in Alt.1.
const struct mystruct *get_reference_2(){
return local_struct;
}
int main()
{
struct mystruct *s = NULL;
// Alt.1
if(get_reference_1(s))
/* Expected Fail*/
else
/* Expected Success*/
// Alt.2
s = get_reference_2()
if(!s)
/* Expected Fail*/
else
/* Expected Success*/
return 0;
}
Maybe i'm thinking wrong and i need to pass a double pointer?
Edit: Corrected with 'const'. Edit2: Updated header.
sis local toget_referenec_1. You have to pass a pointer to the poitner you want to update.local_struct"? Are you trying to confuse the enemy?