Skip to content

Instantly share code, notes, and snippets.

@oguz-ismail
Created January 18, 2023 13:14
Show Gist options
  • Save oguz-ismail/c4722ace23f614c5e181e3e5b7054cfa to your computer and use it in GitHub Desktop.
Save oguz-ismail/c4722ace23f614c5e181e3e5b7054cfa to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <ctype.h>
#include <strings.h>
static int
is_palindromic(const char *str, size_t n) {
size_t i, j;
if (n == 0)
return 1;
i = 0;
j = n - 1;
while (1) {
while (i < j && !isalpha(str[i]))
i++;
while (i < j && !isalpha(str[j]))
j--;
if (i >= j)
break;
if (tolower(str[i]) != tolower(str[j]))
return 0;
i++;
j--;
}
return 1;
}
int
main(int argc, char *argv[]) {
int i;
for (i = 1; i < argc; i++) {
fputs(argv[i], stdout);
if (is_palindromic(argv[i], strlen(argv[i])))
puts(" is a palindrome.");
else
puts(" is not a palindrome.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment