samedi 30 septembre 2017

C++ palindrome not working

I wanted to create function that returns true/false according if the input is a palindrome or not, when given abcddcba or aba it does not give true, but it should . plz help

bool checkPalindrome(char input[],int p=0) {
    if(input[1]=='\0'){
        return true;
    }
    if(sizeof(input)%2==0) { 
        int a = sizeof(input); 
        for(int i=0;i<(a/2);i++) {  
            if(input[0+i]==input[a-i-2]){
                p++;
            }
        }
        if(p==a/2){
            return true;
        } else{
            return false;
        }
    }
    else{
        int a = sizeof(input); 
        for(int i=0;i<((a-1)/2);i++)
        {
            if(input[0+i]==input[a-i-2]){
                p++;
            }
        }
        if(p==(a-1)/2){
            return true;
        } else{
            return false;
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire