Electrical Engineering Question:
Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom")

Answer:
/* BEGIN C SNIPET */
#include
void is_palindrome ( char *in_str ) {
char *tmp_str;
int i, length;
length = strlen ( *in_str );
for ( i = 0; i < length; i++ ) {
*tmp_str[length-i-1] = *in_str[i];
}
if ( 0 == strcmp ( *tmp_str, *in_str ) ) printf ("String is a palindrome");
else printf ("String is not a palindrome");
}
/* END C SNIPET */
#include
void is_palindrome ( char *in_str ) {
char *tmp_str;
int i, length;
length = strlen ( *in_str );
for ( i = 0; i < length; i++ ) {
*tmp_str[length-i-1] = *in_str[i];
}
if ( 0 == strcmp ( *tmp_str, *in_str ) ) printf ("String is a palindrome");
else printf ("String is not a palindrome");
}
/* END C SNIPET */
Previous Question | Next Question |
In C, explain the difference between the & operator and the * operator? | Write a function to output a diamond shape according to the given (odd) input? |