An array isn't a pointer in c. You can't write something like
char s[180]; ++s;
and sizeof s returns 180
Any time you pass an array into a function it decays into a pointer.
Printable View
An array isn't a pointer in c. You can't write something like
char s[180]; ++s;
and sizeof s returns 180
Any time you pass an array into a function it decays into a pointer.
OK, thanks for clearing that up - I misunderstood
Deckard, thnx for your code. But my goal is to write a recursive function, i already knew the iterative way, but i realy find difficult in using recursive functions in this .
YES YES YES i finally got it, worked out the solution for palindrome, the key was just to add 2 more arguments to the function. Here's the code and thnx for all help from start to finish.
Code:#include <stdio.h>
#define SIZE 6
int palindrome( char string[], int start, int end );
int main()
{
char string[ SIZE ] = "radar";
if ( palindrome( string, 0, SIZE - 2 ) == 1 )
printf( "It IS a palindrome.\n" );
else
printf( "It is NOT a palindrome.\n" );
getch();
return 0;
}
int palindrome( char string[], int start, int end )
{
int length = 0;
int i = 0;
if ( start == end )
return 1;
while ( string[ i++ ] != '\0' )
length++;
if ( length - 1 == 1 || length - 1 == 0 )
return 1;
else if ( string[ start ] != string[ end ] )
return 0;
else
return palindrome( string, start + 1, end - 1 );
}