Mail Archives: djgpp/1999/03/14/15:10:58
From: | "Ron Higgins" <ron AT west29 DOT freeserve DOT co DOT uk DOT nospam>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Newbie Pointers
|
Date: | Sun, 14 Mar 1999 19:27:13 -0000
|
Organization: | Customer of Planet Online
|
Lines: | 59
|
Message-ID: | <7ch367$frr$1@news4.svr.pol.co.uk>
|
NNTP-Posting-Host: | modem-91.amlodipine.dialup.pol.co.uk
|
X-Trace: | news4.svr.pol.co.uk 921440263 16251 62.136.50.219 (14 Mar 1999 19:37:43 GMT)
|
NNTP-Posting-Date: | 14 Mar 1999 19:37:43 GMT
|
X-Complaints-To: | abuse AT theplanet DOT net
|
X-Newsreader: | Microsoft Outlook Express 4.72.3110.1
|
X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
The Exercise
Define a character array and use "strcpy" to copy a string into it. Print
the string out by using a loop with a pointer to print out one character at
a time.
Initialise the pointer to the first element and use the double plus sign to
increment the pointer. Use a seperate integer variable to count the
characters to print.
b) Modify the program to print out the string backwards by pointing to the
end and using a decrementing pointer.
After a time getting CRAZY I decided to do it just using arrays and came up
with this ,
main()
{
static char ar1[16];
char *ptr1; /* this was from my attempt using pointers, ignore */
int count;
strcpy(ar1,"This is a string");
for (count=0;count<16;count++) {
printf("%c\n",ar1[count]);
}
for (count=15;count>-1;count--) {
printf("%c\n",ar1[count]);
}
}
which would be fine if the exercise didn't mention pointers :(
my mind is going along the lines : ptr1=ar1;
while (ptr1
!=0(???))
printf("%c\n",ptr1);
ptr++;
but this list lots of ascii characters
b) ptr1=ar1[15]
while (ptr1
!=something???)
printf("%c\n",ptr);
ptr--;
I don't know whether I am miles away or close to solving the problem
--
L8ter, Ron
--
L8ter, Ron
- Raw text -