-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalidrome.c
More file actions
35 lines (28 loc) · 734 Bytes
/
palidrome.c
File metadata and controls
35 lines (28 loc) · 734 Bytes
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAX_PAL_LEN 20
bool is_palindrome(const char[]);
/* supposed to return |true| i.e. 1 if the given string is a palindrome,
* |false| i.e. 0 otherwise.
*/
int
main()
{
const char data[][MAX_PAL_LEN] =
{ "hello", "a", "did", "noon", "level", "redder", "" };
for ( unsigned int i = 0 ; i < sizeof data / sizeof *data ; ++i )
printf("is_palindrome(\"%s\"): %i\n", data[i], is_palindrome(data[i]));
}
bool
is_palindrome(const char s[])
{
int l = strlen(s);
for ( int i = 0 ; i < l/2 ; ++i ){
printf("%c and %c\n",s[i], s[l-i]);
if ( s[i] != s[l-i] )
return false;
}
return true;
}