Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. /*********************************
  2. * Class: MAGSHIMIM C2 *
  3. * Week 1 *
  4. **********************************/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. #define MAX_LENGTH 10
  11.  
  12. int isUpper(char c);
  13. void split(char word[]);
  14. void getWordInput(char word[]);
  15.  
  16. int main(void)
  17. {
  18. char word[MAX_LENGTH] = "";
  19.  
  20. // Getting the word from user
  21. getWordInput(word);
  22.  
  23. split(word);
  24. getchar();
  25.  
  26. return 0;
  27. }
  28.  
  29. /*
  30. The function gets word input from the user
  31.  
  32. Input:
  33. Word
  34.  
  35. Output:
  36. None
  37. */
  38. void getWordInput(char word[])
  39. {
  40. printf("Enter a string with upper and lower case letters: ");
  41. fgets(word, MAX_LENGTH, stdin);
  42.  
  43. // Getting rid of '\n'
  44. word[strcspn(word, "\n")] = 0;
  45. }
  46.  
  47. /*
  48. The function splits the word to upper and lower words
  49.  
  50. Input:
  51. Word
  52.  
  53. Output:
  54. None
  55. */
  56. void split(char word[])
  57. {
  58. int i = 0;
  59.  
  60. char upper[MAX_LENGTH] = "";
  61. char lower[MAX_LENGTH] = "";
  62.  
  63. for (i = 0; i < strlen(word); i++)
  64. {
  65. if (isUpper(word[i]))
  66. {
  67. strcat(upper, word[i]);
  68. }
  69.  
  70. else
  71. {
  72. strcat(lower, word[i]);
  73. }
  74. }
  75.  
  76. printf("The upper and the lower case words:\n%s\n", lower);
  77. }
  78.  
  79. /*
  80. The function checks whether a char is upper case
  81.  
  82. Input:
  83. Char
  84.  
  85. Output:
  86. True or False
  87. */
  88. int isUpper(char c)
  89. {
  90. int isUpper = 0;
  91.  
  92. if (c >= "A" && c <= "Z")
  93. {
  94. isUpper = 1;
  95. }
  96.  
  97. return isUpper;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement