palindrom - doesn't work...

This is a discussion on palindrom - doesn't work... within the C Programming forums, part of the General Programming Boards category; Hi. i'm trying to make it work, i'm sitting already 3 hours and don't really understand where is the problem. ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    palindrom - doesn't work...

    Hi.

    i'm trying to make it work, i'm sitting already 3 hours and don't really understand where is the problem.
    anybody can help with that please?

    Code:
    #include <string.h>
    #include <stdio.h>
    #include <ctype.h>
    #define MAXLEN 400
    
    int polindrom (char s[]);
    
    int main(void) {
    	int type;
    	char isPolindrom [MAXLEN] = {'\0'};
    	int i;
    	printf ("enter your polindrom in one line, up to 400 character \n");
    
    	for (i = 0; i<MAXLEN - 1 && ((type = getchar())!= EOF); i++) {
    		if isalpha (type){
    				if islower (type)
    						type = toupper (type);
    				isPolindrom[i] = type;
    		}
    		else
    			i--;
    	}
    	if (!(isalpha (type)))
    		i++;
    	isPolindrom[i] = '\0';
    	if (polindrom (isPolindrom))
    		printf ("your string is polindrom");
    	else
    		printf ("your string is not polindrom");
    }
    
    int polindrom (char s[])
    {
    	char endCounter;
    	char startCounter;
    	int polindrom = 1;
    	for (endCounter = 0; endCounter !=('\0'); endCounter++) {
    	}
    	for (startCounter = 0; endCounter >0; startCounter++, endCounter--) {
    			if ('s[startCounter]' != 'c[endCounter]')
    				polindrom = 0;
    	}
    	return polindrom;
    }
    thank you

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,498
    Take the quotes off of s[startCounter] and c[endCounter], the latter of which should probably be s[endCounter]. Single quotes define a character literal, like 'Q', where you want the letter Q instead of a variable named Q.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Some other problems is endCounter, that is first assigned 0, then immediately compared against != 0. It's never assigned to anything that have anything to do with the string.

    Then c[] doesn't seem to appear inside your palindrome function, should probably be s[] in both cases.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

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