califguy

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 ?

Ancient Dragon 5,243

temp.a is NOT a pointer, so line 18 can't work.

``````int x=0;

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

Narue 5,707

>Here's the doubt.
You don't have a doubt, you have a question. To have a doubt means that you understand something, and subsequently disagree with it. A question, on the other hand, suggests incomplete understanding and a need or request for clarification. In some cases question can be used in place of doubt, such as "I question your ability to write this code", but in cases similar to "I have a question", doubt cannot be used in place of question.

This is generally a mistake made by people whose native language is not English, especially when using dictionaries that fail to make the distinction of doubt pertaining to a belief rather than an inquiry.

Aia 1,977

>To have a doubt means that you understand something, and subsequently disagree with it.
I doubt the correctness of this statement. Since doubt can arise out of uncertainty, due to lack of understanding.

Narue 5,707

>I doubt the correctness of this statement.
I doubt it's possible to explain the difference in one sentence without being inaccurate. That's probably why so many people have trouble with doubt and question. How about this instead: To have a doubt means you distrust or are skeptical of something.

califguy

temp.a is NOT a pointer, so line 18 can't work.

``````int x=0;

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

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.