#include <stdio.h>
#include <ctype.h>
 
int isPalindrome( char *str, int length )
{
 
   if ( length < 1 )
   {
      return 1; /* no more chars to compare, its a palindrome */
   }
 
   if ( str[0] == str[length-1] )            /* Are the two ends same? */
   {
      return isPalindrome( str+1, length-2 ); /* continue checking */
   }
   else
   {
      return 0;      /* comparison failed, not a palindrome */
   }
}
 
void strToUpper( char *src )
{
   /* convet to upper case any letter */
   while( ( *src = toupper( *src ) ) != '\0' )
   {
      ++src;
   }
}
 
int main( void )
{
   int result = 0;
   char str[40] = { '\0' };
 
   printf( "Please type the string to identify Palindrom or not: ", stdout );
   fflush( stdout );
 
   fgets( str, sizeof str, stdin );
   strToUpper( str );   /* make all letters the same for comparison */
   result = isPalindrome( str, ( strlen( str ) - 1 ) ); /* recursive starts here */
 
   if( result == 1 )
   {
      printf( "1" );
   }
   else
   {
      printf( "0" );
   }
 
   getchar();
   return 0;
 
 }

I wrote this code in c++ but now I wanna switch it to c...It works perfectly fine in c++..
But I kind a forget c functions. Can someone help me and building a code for me in c???

It looks to me like its already in C.

May be but I m not familiar or learned get or put yet. Is there any other way to do it???

May be but I m not familiar or learned get or put yet. Is there any other way to do it???

Then google for those functions and find out what they do. If you want to program then you need to learn how to do your own research.

May be but I m not familiar or learned get or put yet. Is there any other way to do it???

So? Why do you need get and put ? What needs to change in your code to make it C rather than C++?

I want use scanf instead of fput or fget??? to make it simple

No you don't. You want to use fgets() to keep it safe. Here's why

And if the code already works, why change it to be simpler? You will (undoubtedly) break it and have a difficult time fixing it.

I gues you dont know...
Well C++ is part of C, you can write C/C++ Programs, you can mix those 2 and will not be any problem for compiler.

:)

commented: has nothing to do with his question. -4

Ya I always do this kind of thing... I guess the only difference between C and C++ is the way they handle output and input. C++ has cout and cin (which I find simpler than scanf and printf in C). So why try to change the code when only the Input Output is different...

Still if you want to do so,
convert all cout statements to printf()


But my suggestion is to keep your code as it is....

Ya I always do this kind of thing... I guess the only difference between C and C++ is the way they handle output and input. C++ has cout and cin (which I find simpler than scanf and printf in C). So why try to change the code when only the Input Output is different...

If that's the only difference, why use C++ at all? Obviously you don't really know the difference between them. It's much more complicated than input & output, which is only a minuscule difference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.