Mail Archives: djgpp/2005/07/07/09:56:49
> 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.
- Raw text -