Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //The defines
  5. #define ZERO 0
  6. #define ONE 1
  7. #define HUNDRED 100
  8. #define HUNDRED_ONE 101
  9.  
  10. //The functions
  11. int changeArray(char palindrom[]);
  12.  
  13. int main()
  14. {
  15. char palindrom[HUNDRED_ONE] = { 0 };
  16. printf("Enter string (max length 100 chars): ");
  17. fgets(palindrom , HUNDRED , stdin);
  18. changeArray(palindrom);
  19. }
  20. /*
  21. This function Makes the Array and check if this Palindrom
  22. input:The array
  23. output:none
  24. */
  25. int changeArray(char palindrom[])
  26. {
  27. int i = ZERO;
  28. int counter = ZERO; // only for bdika
  29. int len = strlen(palindrom) - ONE;
  30. int left = 0;
  31. int right = len - 1;
  32. while(left < right)
  33. {
  34. if(palindrom[left] != 32)
  35. {
  36. // if Aviel, while 0 < 4 for start
  37. if(palindrom[left] != palindrom[right])
  38. {
  39. printf("not a Palindrome");
  40. return;
  41. }
  42. else
  43. {
  44. left++; // Aviel => A -> v
  45. right--; // Aviel => l -> e
  46. }
  47. }
  48. else
  49. {
  50. left++;
  51. }
  52. if(palindrom[right] == 32)
  53. {
  54. right--;
  55. }
  56. }
  57. //if the array is palindrom
  58. printf("Palindrom");
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement