diff options
Diffstat (limited to 'simple-C-programs/NewPalindrome.c')
| -rw-r--r-- | simple-C-programs/NewPalindrome.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/simple-C-programs/NewPalindrome.c b/simple-C-programs/NewPalindrome.c new file mode 100644 index 0000000..e2402da --- /dev/null +++ b/simple-C-programs/NewPalindrome.c @@ -0,0 +1,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; +}
\ No newline at end of file |
