-
-
Save delor/487123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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