Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* string-case.c */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <string.h>
- void helpMessage(){
- printf("usage: ./string-case [-luh] <<< <String>\n");
- printf("-l Convert to lower case\n");
- printf("-u Convert to upper case\n");
- printf("-h Print help message\n");
- }
- void stringMod(char c,char *string){
- for(int i = 0; i < strlen(string); i++)
- {
- if(c == 'l'){
- putchar(tolower(string[i]));
- }
- if(c == 'u'){
- putchar(toupper(string[i]));
- }
- }
- printf("\n");
- }
- int
- main(int argc, char *argv[])
- {
- int c; //Switch Controller
- int o = -2; //Used to check if no option was provided, will print help message
- char string[100];
- while ( (c = getopt (argc, argv, ":hul")) != -1)
- {
- switch (c)
- {
- case 'h':
- helpMessage();
- break;
- case 'l':
- gets(string);
- stringMod('l', string);
- break;
- case 'u':
- gets(string);
- stringMod('u', string);
- break;
- }
- o = 0;
- }
- if (o == -2){
- helpMessage(); //prints help message if no option was chosen
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement