Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX 101
  5.  
  6. void word();
  7. void check(char word[]);
  8.  
  9. int main()
  10. {
  11.  
  12. word();
  13.  
  14. return 0;
  15. }
  16.  
  17. /*
  18. This function scans
  19. a word from the user
  20. and removes the spaces.
  21. */
  22. void word()
  23. {
  24. char word[MAX] = {0}; //setting strings
  25. int length = 0; //setting variables
  26. int i = 0;
  27. int j = 0;
  28. int iBackup = 0;
  29.  
  30. printf("Please enter a word (100 characters max): "); //Getting a word and it's length
  31. fgets(word, MAX, stdin);
  32. length = strlen(word);
  33. word[length - 1] = 0;
  34.  
  35.  
  36. while(i < MAX) //checking every single place for a space
  37. {
  38. if(word[i] == ' ')
  39. {
  40. iBackup = i;
  41. word[i] = 0; //changing space to NULL
  42. while(i < length) //moving NULL to the last place
  43. {
  44. j = i + 1;
  45. word[i] = word[j];
  46. i++;
  47. }
  48. i = iBackup;
  49. length -= 1 ;
  50. }
  51.  
  52. i++;
  53. }
  54.  
  55. check(word);
  56.  
  57. }
  58.  
  59.  
  60. /*
  61. This function gets the word without spaces
  62. and checks if they are palandromes
  63. */
  64. void check(char word[])
  65. {
  66. int i = 1; //setting variables
  67. int length = 0;
  68. int count = 0;
  69.  
  70. length = strlen(word);
  71. while(i <= length/2)
  72. {
  73. if(word[i-1] == word[length - i]) //checking for palandromes
  74. {
  75. count++;
  76. }
  77. i++;
  78. }
  79.  
  80. if(count == length/2)
  81. {
  82. printf("Yes\n");
  83. }
  84. else
  85. {
  86. printf("No\n");
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement