cancel
Showing results for 
Search instead for 
Did you mean: 

pointer

Rahimi.Meysam
Associate II
Posted on September 22, 2015 at 18:24

Hello. 

i have this structure definition:(ex)

structure example_str

{

int a[10];

int b[10];

}

and a function with this definition:

void test(example_str *temp);

 i want to change the value that pointer temp is locating with out using another variable to define.

(not to do like this:

example_str test = * temp.

test.a[1] = 10 ;

)

i want to define arrays value directly.

I would be very thankful if everybody help me.

thank you

#pointer
3 REPLIES 3
Posted on September 22, 2015 at 18:37

Not 100% sure of what the question is, let's start with something that makes sense and discuss from there.

typedef struct _example_str {
int a[10];
int b[10];
} example_str;
void test(example_str *temp, int x)
{
temp->a[1] = x;
}
int main(void)
{
example_str foo = { 0 }; // cleared
example_str bar = { 0 }; // cleared
test(&foo, 11);
printf(''%d
'', foo.a[1]);
test(&bar, 22);
printf(''%d
'', bar.a[1]);
while(1);
return(0);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 22, 2015 at 18:40

Or are you looking to do this?

example_str foo = { {1, 2, 3}, {4, 5, 6} }; 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rahimi.Meysam
Associate II
Posted on September 23, 2015 at 07:46

Thank you Clive. In this post you answer me clearly and problem solved.

thank you again..