-
Notifications
You must be signed in to change notification settings - Fork 0
/
palindrome.c
43 lines (34 loc) · 928 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
42
43
/**********************************************************************************
File name: palindrome.c
Author: Johan Andrade
Date created: 02 / 23 / 2021
Date last modified 08 / 15 / 2021
Description: The function checks for palindrome words.
Refer to README.md for full description.
**********************************************************************************/
#include <stdio.h>
#include <string.h>
char p[20];
void checkPalindrome();
int main()
{
printf("Enter a string to check if it is a palindrome: ");
scanf("%[^\n]s", p); // strings with spaces are allowed
printf("The string entered is: %s. \n", p);
checkPalindrome(p);
return 0;
}
void checkPalindrome()
{
char r[] = "";
strcpy(r, p);
strrev(r);
if (strcmp(p, r) == 0)
{
printf("The string '%s' is a palindrome. \n", p);
}
else if (strcmp(p, r) != 0)
{
printf("The string '%s' is not a palindrome. \n", p);
}
}