Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include"myInputManager.h"
- #include<string.h>
- //#pragma warning(disable:4996)
- #define STRINGLENGTH 100
- /*This funktion creates a reversed coppy of the selected strring and checks if they are equal*/
- int IsPalindrome(char inputString[])
- {
- char inputCopy[STRINGLENGTH];
- int len = strlen(inputString);
- int end = len - 1;
- for (int i = 0; i < len; i++) {
- inputCopy[i] = inputString[end - i ];
- if (inputCopy[i] != inputString[i])
- return 0;
- }
- return 1;
- }
- /*This funktion reconstructs a string whithout all special signs(space, /, numbers, m.m.)*/
- void ReconstString(char inputString[])
- {
- int size = strlen(inputString) + 1, j = 0;
- for (int i = 0; i < size; i++)
- if (isalpha(inputString[i]) != 0 || inputString[i] == '\0')
- {
- inputString[j++] = inputString[i];
- }
- }
- /*This funktion tursns all the letters in a string to lower case if a lower case is awailable*/
- void ToLowerCString(char inputString[])
- {
- for (int i = 0; i < strlen(inputString); i++)
- inputString[i] = tolower(inputString[i]);
- }
- /*This funktion brings it all toether by taking the raw input string and transforming and checkin if it is inded a palindrome*/
- int CheckPalindrome(char inputString[])
- {
- ReconstString(inputString);
- ToLowerCString(inputString);
- if (IsPalindrome(inputString) == 1)
- return 1;
- else
- return 0;
- }
- int main(void)
- {
- char check = 'n', inputString[STRINGLENGTH];
- do
- {
- printf("Input a text and i will check if it is a palindrome: ");
- scanString(inputString, STRINGLENGTH);
- if (CheckPalindrome(inputString) == 1)
- printf("\nYes it's a palindrome.\n");
- else
- printf("\nNo it's not a palindrome.\n");
- printf("If you wan't to test another word? (y/n) ");
- scanChar(&check);
- printf("\-------------------------------------------------\n");
- } while (check == 'y');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement