Interview Questions

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

Electrical Engineering Technical Interview Questions and Answers


(Continued from previous question...)

13. Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom").

/* 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 */

(Continued on next question...)

Other Interview Questions