Skip to content

Instantly share code, notes, and snippets.

@jleeothon
Last active August 29, 2015 14:06
Show Gist options
  • Save jleeothon/69d744398b805e591a0a to your computer and use it in GitHub Desktop.
Save jleeothon/69d744398b805e591a0a to your computer and use it in GitHub Desktop.
C: is palindrome
#include <stdio.h>
#define palsize 100
/*
* Returns 1 if is a pure palindrome.
* The name is a bit mangled up because good C code shouldn't be understandable.
*/
int ispaldrm(char* s)
{
char *a = s, *b = s;
while (*b) {
b++;
}
b -= 1;
while (a < b) {
if (*a++ != *b--) {
return 0;
}
}
return 1;
}
int main()
{
char s[palsize];
gets(s);
if (ispaldrm(s)) {
puts("Well, yes");
} else {
puts("Nope");
}
return 0;
}
@jleeothon
Copy link
Author

gets is dangerous and the compiler might complain but I'm putting it for sake of simplicity against scanf("%s", s);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment