Mail Archives: djgpp/1999/03/14/19:45:06
Firstly, your working program has a bug; the array is not large
enough to hold the string. You allocated 16 characters, and
filled them all with the string; there is no room for the
terminating zero character. Never forget to allocate the extra
space for this.
More comments interspersed below.
On 14 Mar 99 at 19:27, Ron Higgins wrote:
> my mind is going along the lines : ptr1=ar1;
> while (ptr1
> !=0(???))
You were told to `Use a separate integer variable to count the
characters to print'. If you want to do it in the way that you
have, you need to dereference since you actually want to look
at the char pointed at, not the pointer itself. `while (*ptr1
!= 0)', or just `while (*ptr1)'.
> b) ptr1=ar1[15]
Again you've got confused between the pointer and what it
points at. Here you try to assign a char value (the 15th
character) to a pointer. You want either:
ptr1 = &ar1[15];
using the address operator to get the address of that object
rather than its value, or more simply (and equivalently):
ptr1 = ar1 + 15;
which works because in this context `ar1' becomes a pointer to
char.
> while (ptr1
> !=something???)
while (ptr1 >= ar1)
... but you were told to use an integer counter again.
> I don't know whether I am miles away or close to solving the problem
You're pretty close. I don't think this list/group is the
right place for this question though; it is not specific to
djgpp at all.
--
George
- Raw text -