Menu
Coddy logo textTech

Practice #5

Lesson 13 of 13 in Coddy's Stack - Data Structures Series #1 course.

The next challenges are designed to use stack in them.

The Stack data structure (storing characters) is already provided for you — use it!

challenge icon

Challenge

Easy

Write a function isPalindrome that gets a string and returns true if the string is a palindrome, otherwise false.

A palindrome is a word or phrase that reads the same backward as forward.

Use the provided Stack to solve this problem!

Try it yourself

#include <stdio.h>
#include <string.h>
#include "solution.h"

int main() {
    char s[1000];
    if (fgets(s, sizeof(s), stdin) == NULL) {
        s[0] = '\0';
    }
    s[strcspn(s, "\r\n")] = '\0';
    printf("%s\n", isPalindrome(s) ? "true" : "false");
    return 0;
}

All lessons in Stack - Data Structures Series #1