X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Date: Thu, 7 Jul 2005 09:55:39 -0400 Message-Id: <200507071355.j67DtdoL008918@envy.delorie.com> From: DJ Delorie To: djgpp AT delorie DOT com In-reply-to: <1120730512.270559.89950@o13g2000cwo.googlegroups.com> (rahul DOT h AT gmail DOT com) Subject: Re: pointers in Strucrure assignment problem References: <1120713425 DOT 526371 DOT 222910 AT g47g2000cwa DOT googlegroups DOT com> <200507070533 DOT j675XMNZ030942 AT envy DOT delorie DOT com> <1120730512 DOT 270559 DOT 89950 AT o13g2000cwo DOT googlegroups DOT com> Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Yes, you are right. Please tell me the solution to solve this problem Instead of changing the *pointer* you need to change the *contents pointed to*. Use a function like strcpy or memmove, or dereference the pointer to fill in the buffer one char at a time. Consider: char buf1[100]; char buf2[100]; char buf3[100]; char *ptr1; char *ptr2; char *ptr3; On most machines, buf1 through buf3 each occupy 100 bytes in memory, each block of which contain 100 bytes of "char" data. ptr1 through ptr3 each occupy FOUR bytes of memory, each of which contain the ADDRESS of some other block of memory. These change the *pointer*: ptr1 = 0; ptr1 = "some string"; ptr1 = buf1; ptr1 = buf2; These change the *contents*: *ptr1 = 0; strcpy (ptr1, "some string"); ptr1[4] = 'a'; Consider: ptr1 = buf1; ptr2 = buf1; Now, if you do "ptr1[4] = 'a';" then ptr2[4] is ALSO 'a' because they both point to the same buffer.