Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /*****************************************************************************************
  2. * PROGRAM: Pluralizer.cpp
  3. * AUTHOR: Zachary Kerns Some portions assisted by David Bowles
  4. * DATE:
  5. * CLASS: CTCH 233 Winter 2011
  6. *
  7. * USAGE: pluralizer.exe
  8. *
  9. * DESCRIPTION:
  10. * The Pluralizer takes nouns and converts them to their plurals.
  11. *
  12. *
  13. *
  14. *****************************************************************************************/
  15.  
  16.  
  17.  
  18.  
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23.  
  24. //Global variables.
  25. int i = 0;
  26. int convert = 1;
  27. char noun[20];
  28. void pluralizer(char *noun);
  29. void endProgram(int convert);
  30.  
  31. int main()
  32. {
  33.  
  34. while (convert !=0)
  35. {
  36. endProgram(convert);
  37. printf("Please enter a noun: ");
  38. scanf("%s", noun);
  39.  
  40. //Start the pluralizing action.
  41. pluralizer(noun);
  42.  
  43. printf("%s\n", noun);
  44. }
  45. return 0;
  46. }
  47.  
  48. void pluralizer(char *noun)
  49. {
  50. int i = strlen(noun);
  51.  
  52.  
  53.  
  54. if ((noun[i - 1] == 's'))
  55. {
  56. strcat(noun, "es");
  57. }
  58. else if ((noun[i - 2] == 'c') && ((noun[i - 1] == 'h')))
  59. {
  60. strcat(noun, "es");
  61. }
  62. else if ((noun[i - 2] == 's') && ((noun[i - 1] == 'h')))
  63. {
  64. strcat(noun, "es");
  65. }
  66.  
  67.  
  68. else if (noun[i - 1] == 'y' )
  69. {
  70. noun[(strlen(noun) - 1)] = '\0';
  71. noun[(strlen(noun) - 1)] = '\0';
  72.  
  73. (strcat(noun, "ies"));
  74. }
  75.  
  76. else
  77. {
  78. strcat(noun, "s");
  79. }
  80.  
  81.  
  82. }
  83. void endProgram(int convert)
  84. {
  85. //Having trouble getting all of this to work
  86. if (strcmp(noun, "done") !=0)
  87. convert = 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement