Skip to main content
Post Closed as "Not suitable for this site" by Emily L., SuperBiasedMan, RubberDuck, Ethan Bierlein, Vogel612
Tweeted twitter.com/StackCodeReview/status/693961957066575873
edited title
Link

Program to ChechCheck If string is Palindrome (in C)

Source Link

Program to Chech If string is Palindrome (in C)

Just wrote a program to check if a string is Palindrome. If that's true, return 1. Else, return 0. How can I improve it?

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int palindrome(char *s)
{
    int i = 0, length = strlen(s) - 1, n = length;
    int boolean = 0;

    for (; i <= length && n >= 0; i++, n--) {
        if (toupper(s[i]) == toupper(s[n]))
            boolean = 1;
        else
            boolean = 0;
    }

    return boolean;
}

int main(void)
{
    char string[] = "Racecar";

    printf("%d", palindrome(string));

    return 0;
}