Advertisement
Guest User

Svart magi for magnus

a guest
Apr 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include<stdio.h>
  2. #include"myInputManager.h"
  3. #include<string.h>
  4. //#pragma warning(disable:4996)
  5. #define STRINGLENGTH 100
  6.  
  7. /*This funktion creates a reversed coppy of the selected strring and checks if they are equal*/
  8. int IsPalindrome(char inputString[])
  9. {
  10. char inputCopy[STRINGLENGTH];
  11. int len = strlen(inputString);
  12. int end = len - 1;
  13. for (int i = 0; i < len; i++) {
  14. inputCopy[i] = inputString[end - i ];
  15.  
  16. if (inputCopy[i] != inputString[i])
  17. return 0;
  18. }
  19.  
  20. return 1;
  21. }
  22.  
  23. /*This funktion reconstructs a string whithout all special signs(space, /, numbers, m.m.)*/
  24. void ReconstString(char inputString[])
  25. {
  26. int size = strlen(inputString) + 1, j = 0;
  27.  
  28. for (int i = 0; i < size; i++)
  29. if (isalpha(inputString[i]) != 0 || inputString[i] == '\0')
  30. {
  31. inputString[j++] = inputString[i];
  32. }
  33. }
  34.  
  35. /*This funktion tursns all the letters in a string to lower case if a lower case is awailable*/
  36. void ToLowerCString(char inputString[])
  37. {
  38. for (int i = 0; i < strlen(inputString); i++)
  39. inputString[i] = tolower(inputString[i]);
  40. }
  41.  
  42. /*This funktion brings it all toether by taking the raw input string and transforming and checkin if it is inded a palindrome*/
  43. int CheckPalindrome(char inputString[])
  44. {
  45. ReconstString(inputString);
  46. ToLowerCString(inputString);
  47. if (IsPalindrome(inputString) == 1)
  48. return 1;
  49. else
  50. return 0;
  51. }
  52.  
  53. int main(void)
  54. {
  55. char check = 'n', inputString[STRINGLENGTH];
  56.  
  57. do
  58. {
  59. printf("Input a text and i will check if it is a palindrome: ");
  60. scanString(inputString, STRINGLENGTH);
  61. if (CheckPalindrome(inputString) == 1)
  62. printf("\nYes it's a palindrome.\n");
  63. else
  64. printf("\nNo it's not a palindrome.\n");
  65.  
  66. printf("If you wan't to test another word? (y/n) ");
  67. scanChar(&check);
  68. printf("\-------------------------------------------------\n");
  69. } while (check == 'y');
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement