-
Notifications
You must be signed in to change notification settings - Fork 1
/
palindrome.c
41 lines (38 loc) · 808 Bytes
/
palindrome.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* MicroStrategy Campus
* Oct 21, 2013
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef TRUE
#undef TRUE
#endif
#ifdef FALSE
#undef FALSE
#endif
typedef enum { FALSE, TRUE } Boolean;
static Boolean palindrome(const char *str) {
assert (str != NULL && *str != '\0');
size_t i = 0, len = strlen(str);
while(i < len/2) {
if (str[i] != str[len-1-i])
return FALSE;
i++;
}
return TRUE;
}
int main(int argc, char *argv[]) {
size_t len, i;
char *p;
if(argc != 2) {
printf("%s <string>\n", argv[0]);
exit(EXIT_FAILURE);
}
printf("Palindrome test for %s: ", argv[1]);
if (palindrome(argv[1]))
printf("Pass\n");
else
printf("Fail\n");
exit(EXIT_SUCCESS);
}