array copying and pointers

hi guys,
I have a simple question and I am new to c, Would appreciate any advise I could get.
Here's the doubt.

main()
{
char a[10],*a1,b[10],*b1;
a1=&a[0];
b1=&b[0];

int x=0;
for (x=0;x<=1-;x++0)
{
*a1++=*b1++;
}

}


Basically if I had a string in b[10] it would get copied to a 10 using the pointers. ( Dunt want to use strcopy as i could have a \0 ) The above method works..


Now if I want to do the same thing but into an array of structures:


struct temp
{
char a[10];
}

main()
{
char b[10],*b1,*k,k1[10];
struct temp m,*n;
n=&m;
b1= &b[0];
b1= "hellohello" ;

int x=0;

for(x=0;x<=9;x++)
{
(*n->a)++ = *b1++;
}
}

This gives me an error.


What I want to do, is copy data from an array I have into an array inside a structure using the pointer method though and not using strcpy. Any suggestions.


 
(*n->a)++


is nonsensical.

Why not just

1
2
3
4
n = &m;
b1 = b;        // same as &b[ 0 ] here
for( int x = 0; x < sizeof( b ); ++x )
   n->a[ x ] = *b1++;


Otherwise you need a destination pointer (a1).


Thanks. Now that i look at it, it makes sense. The-> notation kinda got me confused and I was using another pointer to an existing pointer.

Thanks for making it clear.
Appreciate your help
Topic archived. No new replies allowed.