Hello again all. Got a question concerning palindromes. Basically I am writing a program that will determine if a line is a palindrome or not, neglecting spaces and punctuation that is. Now I am trying to do this by setting two variables on each end of the string and comparing the two. Now I can compare the first two fine using an if, but I'm a little unclear as to how I would increase my said variables, and then disregard punctuation and spaces. I know that i would need to use a while loop but I dont know what arguments to use. Thanks for the help.

Scratch that, did some more research which solved some of my problem, but still am lacking on how to remove punctuation and spaces.

9 Years
Discussion Span
Last Post by Hamrick

Just don't compare the two variables if one is a space or punctuation.

while ( i < j ) {
  if ( isvalid( string, i ) && isvalid( string, j ) ) ) {
    if ( string[i++] != string[j++] ) {
      printf( "Not a palindrome\n" );
  }else {
    if ( !isvalid( string[i] ) ) {

    if ( !isvalid( string[j] ) ) {

isvalid is a placeholder for whatever you write to test that a character isn't a space or punctuation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.