Passing structure pointer within structures

  • Thread starter Thread starter kunal s patel
  • Start date Start date
K

kunal s patel

Hi,
I am new to C programming. Here is what I am trying to do

typedef struct A {
char *a;
}A;

struct B {
int b;
A *asample;
};


void main()
{
struct B bk;
}

Now I want to allocate Hello to bk->asample->a. How do I proceed here. Any
help will be appreciated

Thanks,
Kunal
 
If this is 'C' as opposed to C++, I think it will be something like this:
bk->asample = (A*)malloc(A);
bk->asample->a = (char*)malloc(somestringsize);
strcpy(bk->asample->a, "this is my string");

This is off the top of my head. I haven't done C and mallocs in twenty
years.
 
If this is 'C' as opposed to C++, I think it will be something like this:
bk->asample = (A*)malloc(A);
bk->asample->a = (char*)malloc(somestringsize);
strcpy(bk->asample->a, "this is my string");

This is off the top of my head. I haven't done C and mallocs in twenty
years.
 
kunal said:
Hi,
I am new to C programming. Here is what I am trying to do

typedef struct A {
char *a;
}A;

struct B {
int b;
A *asample;
};


void main()
{
struct B bk;
}

Now I want to allocate Hello to bk->asample->a. How do I proceed here. Any
help will be appreciated

Kunal:

Please don't multi-post. This is not a question about the .NET language C++/CLI
so it does not belong here. The group

microsoft.public.vc.language

is more suitable.
 
kunal said:
Hi,
I am new to C programming. Here is what I am trying to do

typedef struct A {
char *a;
}A;

struct B {
int b;
A *asample;
};


void main()
{
struct B bk;
}

Now I want to allocate Hello to bk->asample->a. How do I proceed here. Any
help will be appreciated

Kunal:

Please don't multi-post. This is not a question about the .NET language C++/CLI
so it does not belong here. The group

microsoft.public.vc.language

is more suitable.
 
Back
Top