From 890c36fd3d33e310ce9c6821f681a383545e694c Mon Sep 17 00:00:00 2001 From: Hyder Date: Sat, 16 Aug 2025 22:37:45 +0300 Subject: Finally i solved this kinda tough exercise i beileve(the palindrome checker), i made it work :D --- Palindrome/Palindrome.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ README | 3 ++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Palindrome/Palindrome.c 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 + +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 -- cgit v1.2.3