Skip to content

Instantly share code, notes, and snippets.

@delor
Forked from bradjohansen/palindrome.c
Created July 23, 2010 07:22
Show Gist options
  • Save delor/487123 to your computer and use it in GitHub Desktop.
Save delor/487123 to your computer and use it in GitHub Desktop.
/**
* @file palindrome.c
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <cs50.h>
bool isPalindrome(char* text);
int main()
{
printf("Enter a word: ");
char* input = GetString();
if (isPalindrome(input))
printf("%s is a palindrome\n", input);
else
printf("%s isn't a palindrome\n", input);
free(input);
return 0;
}
/**
* Test if text is palindrome (case sensitive).
* @returns @c true if @p text is palindrome, @c false otherwise
*/
bool isPalindrome(char* text)
{
int start = 0;
int end = strlen(text) - 1;
while (start < end)
if (text[start++] != text[end--])
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment