Palindromes

This is a discussion on Palindromes within the C Programming forums, part of the General Programming Boards category; Ive searched the board and seen the other palindrome examples but its too complex for me. Ive implemented my own ...

  1. #1
    cman
    Guest

    Palindromes

    Ive searched the board and seen the other palindrome examples but its too complex for me. Ive implemented my own but i have an error which bugs me.

    C:\src\palindromes\palindromes.c(117) : warning C4133: 'function' : incompatible types - from 'int [1000]' to 'const char *'

    something wrong with my remblanks, but ive done the same operation in most of the other functions, i dont see why its happening here.

    Anyone see whats wrong with my code?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    #define SIZE 1000
    
    void get_sentence( char [] );
    int is_palindromes( char [] );
    void lower( char [] );
    void reverse( char [] );
    void remblanks( char [] );
    
    int main()
    {
    	char words[SIZE];
    	get_sentence(words);
    	if (is_palindromes(words))
    	{
    		printf( "%s is a palindrome!\n", words );
    	} else {
    		printf( "%s is NOT a palindrom!\n", words );
    	}
    	return 0;
    }
    
    void get_sentence( char words[] )
    {
    	int ch;
    	int n=0;
    	printf( "Enter your sentence:\n" );
    	while ( (ch=getchar()) != '\n' ) {
    		words[n] = ch;
    		n++;
    	}
    	words[n] = '\0';	/* insert null at end of string */
    }
    
    int is_palindrome( char words[] )
    {
    	char x[SIZE], temp[SIZE];
    	int i, n=0, palin;
    	strcpy( x, words );
    	strcpy( temp, words );
    	reverse ( x );
    	lower( x );
    	lower( temp );
    	remblanks( x );
    	remblanks( temp );
    	for ( i=0; i<n; i++ ) {
    		if ( x[i] == temp[i] ) {
    			palin=1;
    		}
    		else {
    			palin=0;
    			break;
    		}
    	}
    
    	return palin;
    }
    
    void lower( char words[] )
    {
    	int i, n=0, size;
    	char temp[SIZE];
    	size = strlen(words);
                    for (i=0; i < size; i++) {
    		if ( islower( words[i] ) ) {
    			temp[n] = words[i];
    			n++;
    		}
    		else {
    			temp[n] = words[i];
    			n++;
    		}
    	}
    
    	strcpy( words, temp );
    }
    
    void reverse( char x[] )
    { 
    	char copyarray[SIZE];
    	int i, n=0;
    	for (i=strlen(x); i>=0; i--) {
    		copyarray[n] = x[i];
    		n++;
    	}
    
    	strcpy( x, copyarray );
    }
    
    void remblanks( char words[] )
    {
    	int temp[SIZE];
    	int i, n=0, size;
    
    	size = strlen(words);
    
    	for ( i=0; i < size; i++ ) {
    		if ( words[i] != ' ' ) {
    			temp[n] = words[i];
    			n++;
    		}
    	}
    
    	strcpy( words, temp );
    }

  2. #2
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    Code:
    int is_palindromes( char [] );
    ...
    int main()
    {
        if (is_palindromes(words))
        ....
    }
    ...
    int is_palindrome( char words[] ) // should be is_palindromes
    ...
    Or just remove the s from "is_palindromes" in the function prototype and from the function call in main.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Palindromes
    By jewelz in forum C++ Programming
    Replies: 57
    Last Post: 02-23-2009, 05:11 PM
  2. Palindromes and Bitwise operators
    By Dr Tornillo in forum C Programming
    Replies: 8
    Last Post: 08-02-2007, 02:31 PM
  3. palindromes and bool
    By justinc911 in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2003, 06:58 PM
  4. palindromes....
    By imbecile in C in forum C Programming
    Replies: 8
    Last Post: 08-09-2003, 05:08 PM
  5. strings and palindrome's
    By watshamacalit in forum C Programming
    Replies: 6
    Last Post: 01-07-2003, 05:17 PM

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