Palindrome, problem with isalpha

This is a discussion on Palindrome, problem with isalpha within the C Programming forums, part of the General Programming Boards category; I don't know if I am implementing isalpha() correctly and doing something else wrong or it's in the wrong place. ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    14

    Palindrome, problem with isalpha (solved)

    I don't know if I am implementing isalpha() correctly and doing something else wrong or it's in the wrong place. Where I have the isalpha now, once I compile and run it, it say everything is palindrome, which is definitely not right. What am I doing wrong?

    Thanks

    Here is the palindrome function, I don't think I need to post the main because it was given by my professor and there is no need to change it. If you need it, just say so.

    Code:
    int is_palindrome(const char *message)
    {
    	
    	int k = tolower(strlen(message) - 1);
    	int j;
    	
    	for(j = 0; j <= k; j++)
    	{
    		if(isalpha(tolower(message[j]) != tolower(message[k]))) 
    		{	
    			return 0;
    		}
          
    	k--;
        
    	}
    	   
    	return 1;
    }
    Last edited by Kyeong; 11-06-2008 at 10:02 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I can think of no valid purpose for isalpha to serve here. The result of != is always either 0 or 1, and neither of those are alphabetical characters in ASCII.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    In other words: "My program is not functioning correctly. I am thinking it is the result of a function that has been widely in-use for almost three decades."

    Does that about sum it up? Because that isn't even a question, buddy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21