blob: e2402da6fc1f5d796c6ff47bb788434f84aa186c (
plain)
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
42
43
44
45
46
47
48
49
|
#include <stdio.h>
#include <string.h>
void reverse(char *destination, char *source) {
int length = strlen(source);
int i;
for(i = 0;source[i] != '\0';i++) {
destination[i] = source[length - 1];
length--;
}
destination[i] = '\0';
}
void palindrom(char *input) {
char tmp_dest[100];
reverse(tmp_dest , input);
for(int i = 0;input[i] != '\0';i++) {
if(input[i] != tmp_dest[i]) {
printf("Not a palindrome\n");
return;
}
}
printf("the word is a palindrome\n");
}
int main() {
char source[100];
char destination[100];
fgets(source, sizeof(source), stdin);
// to lowerCase the input letters
for(int i = 0;source[i] != '\0';i++) {
if(source[i] >= 'A' && source[i] <= 'Z') {
source[i] += 32;
}
}
source[strcspn(source, "\n")] = '\0';
palindrom(source);
return 0;
}
|