On Sun, Nov 23, 2008 at 12:30 PM, John Matthews <[EMAIL PROTECTED]> wrote:
> --- In [email protected], "John Matthews" <[EMAIL PROTECTED]> wrote:
>>
>> --- In [email protected], "Ahmed Shabana" <UnlimitedEng@> wrote:
>> >
>> > okay what is the solution of this problem ???????/
>> > HOW can I assign the variable which called "name"
>>
>> Example:
>>
>> int main()
>> {
>> struct sub sub0;
>> struct maiN s0;
>>
>> s0.s1 = &sub0;
>> s0.c = 42;
>>
>> strcpy(s0.s1->name,"hi man ");
>> printf("name: %s\nvalue: %d\n", s0.s1->name, s0.c);
>>
>> return 0;
>> }
>
> ...or alternatively use dynamic memory allocation:
Or get rid of the problem altogether so you don't have to 'remember'
to do anything, and change the containing struct:
struct maiN {
struct sub s1; /* changed from pointer to the object itself */
int c;
};
Making the code in the OP work as expected (changing the redirection of course):
int main()
{
struct maiN s0;
strcpy(s0.s1.name,"hi man ");
return 0;
}
--
PJH
http://shabbleland.myminicity.com/tra