simo said:
was needing to build an array that prints backwards ( stringReverse )
and returns nothing. should stop processing and print nothing when null
is encountered. this is what i have so far. was going to build my
function from the call but could not make it compile from this point.
I've modified your code somewhat. In its current state, it will compile and
run - but it won't reverse the string. All you have to do is write in the
details of stringReverse - which is a poor name choice for an abstruse
technical reason but we'll let that slide for now.
#include <stdio.h>
void stringReverse(char *s)
{
/* 1. find the length of the input - if it's
0 or 1, forget it and return. */
/* 2. get a marker (A) - a pointer or an index - to indicate
the first character in the string */
/* 3. get a marker (B) - a pointer or an index - to indicate
the last character before the null terminator */
/* 4. you'll need a temporary swap space too - a single char will do */
/* 5. for as long as marker A and marker B haven't yet collided... */
{
/* 6. copy the last unswapped-so-far value from
marker B into your temp */
/* 7. copy the first unswapped-so-far value
from marker A to marker B */
/* 8. copy the saved value from the
temp to marker A */
/* 9. add 1 to marker A */
/* 10. subtract 1 from marker B */
}
}
int main(void)
{
char strArray[] = "Print this string backwards.";
printf( "%s\n", strArray);
stringReverse( strArray );
printf( "%s\n", strArray);
return 0;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.