aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Palindrome/Palindrome.c50
-rw-r--r--README3
2 files changed, 52 insertions, 1 deletions
diff --git a/Palindrome/Palindrome.c b/Palindrome/Palindrome.c
new file mode 100644
index 0000000..5cb3c97
--- /dev/null
+++ b/Palindrome/Palindrome.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+
+char *reverse(char *input) {
+ int len = -1;
+ for (int i = 0;input[i] != '\0'; i++) {
+ len += 1;
+ }
+ for (int i = 0;i <= len;i++) {
+ char tmp = input[i];
+ input[i] = input[len];
+ input[len] = tmp;
+ len--;
+ }
+ return input;
+}
+
+void compareString(char *input1, char *input2) {
+ int len = -1;
+ int flags = 0;
+ for (int i = 0;input1[i] != '\0';i++) {
+ len += 1;
+ }
+ for (int i = 0;i <= len;i++) {
+ if (input1[i] == input2[len]) {
+ flags = 1;
+ len--;
+ }
+ else {
+ flags = 0;
+ printf("Not a palindrome\n\n");
+ break;
+ }
+ }
+ if (!flags == 0) {
+ printf("This is a palindrome\n\n");
+ }
+}
+
+
+int main()
+{
+
+ printf("Get me a word to see if it is a palindrome\n\n");
+ char inp[1000];
+ while (scanf("%s", inp) != EOF) {
+ char *tmp = reverse(inp);
+ compareString(inp, tmp);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/README b/README
index debff5d..1a85d40 100644
--- a/README
+++ b/README
@@ -10,4 +10,5 @@ CONTENTS
- The greatest common divisor exercise solution, in ROOT/GCD/GCD.c
- Hexadecimal to integer converter solution, in ROOT/HTOI/HTOI.c
- Vowels and consonants counter of a string, in ROOT/VACC/VowelsAndConsonantCounter.c
-- Binary(28-bit) to decimal converter, in ROOT/BTD/28bitToDecimal.c \ No newline at end of file
+- Binary(28-bit) to decimal converter, in ROOT/BTD/28bitToDecimal.c
+- Palindrome words checker exercise, in ROOT/Palindrome/Palindrome.c \ No newline at end of file