[Courses] [C] What is wrong here??
lbowser at andrew.cmu.edu
Tue Aug 13 09:33:04 EST 2002
>char strrev(char array)
> register int i;
> return *array;
I'm mildly suprised this compiles without warnings because you say you return
a char, but you're returning a pointer to an array.
so you're returning a pointer to an array which is a pointer to a char
(return value) -> array -> (char) array
if you want to access the value you're returning you'd have to access it as
When you're dealing with pointers (especially at first) DRAW WHAT MEMORY LOOKS
LIKE! It will really save you some headaches, and eventually, you'll be able
to know what's going on without drawing the pictures. Heck, I've been
programming in C for almost 7 years now and I still draw pretty pictures to
help me out :)
What looks like is happening is that you're returning the first character and
that's it. I think you're attempting to write a recursive function, but
you're not quite there yet.
Hope this helps,
Public Key available at
More information about the Courses