Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************
- * Class: MAGSHIMIM C2 *
- * Week 1 *
- **********************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_LENGTH 10
- int isUpper(char c);
- void split(char word[]);
- void getWordInput(char word[]);
- int main(void)
- {
- char word[MAX_LENGTH] = "";
- // Getting the word from user
- getWordInput(word);
- split(word);
- getchar();
- return 0;
- }
- /*
- The function gets word input from the user
- Input:
- Word
- Output:
- None
- */
- void getWordInput(char word[])
- {
- printf("Enter a string with upper and lower case letters: ");
- fgets(word, MAX_LENGTH, stdin);
- // Getting rid of '\n'
- word[strcspn(word, "\n")] = 0;
- }
- /*
- The function splits the word to upper and lower words
- Input:
- Word
- Output:
- None
- */
- void split(char word[])
- {
- int i = 0;
- char upper[MAX_LENGTH] = "";
- char lower[MAX_LENGTH] = "";
- for (i = 0; i < strlen(word); i++)
- {
- if (isUpper(word[i]))
- {
- strcat(upper, word[i]);
- }
- else
- {
- strcat(lower, word[i]);
- }
- }
- printf("The upper and the lower case words:\n%s\n", lower);
- }
- /*
- The function checks whether a char is upper case
- Input:
- Char
- Output:
- True or False
- */
- int isUpper(char c)
- {
- int isUpper = 0;
- if (c >= "A" && c <= "Z")
- {
- isUpper = 1;
- }
- return isUpper;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement