palindrome.c
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004
00005
00006 int palindrome(char * mot) {
00007 size_t n = strlen(mot), i;
00008 for (i = 0; i <= n/2; i++) {
00009 if (mot[i] != mot[n-1-i]) return 0;
00010 }
00011 return 1;
00012 }
00013
00014 int main(int argc, char * argv[])
00015 {
00016 if (argc < 2) {
00017 printf("Usage: %s mot1 mot2...\n",argv[0]);
00018 return EXIT_FAILURE;
00019 }
00020 int i;
00021 for (i = 1; i < argc; i++)
00022 printf("Le mot \"%s\" %s un palindrome\n",
00023 argv[i], palindrome(argv[i])?"est":"n'est pas");
00024 return 0;
00025 }