Question

Basically this is a switch case menu program. I'm put the enter a string functions before the menu part to keep it organized. My main issue at the moment is case 4. What I'm trying to do is make a function that converts a whole string into uppercase. But i can't seem to find a way to apply it to the entered string. It only works if i define a predetermined string.

const int CSTR_MAX = 33;        

void readCString(char cs[])
{
printf("Enter a character string up to %i characters:  ", CSTR_MAX-1);
scanf("%s", cs);
}


int main(int argc, const char * argv[])
{
@autoreleasepool {

    char cstr[CSTR_MAX];
    int choices;
    BOOL done=FALSE;         
    NSString *obj;
    NSString *uppercase = (Imnotsurewhatneedstogohere);
    NSString *lowercase;

    readCString(cstr);

    do {
        //Print the menu and prompt the use for the selection
        printf("\nMenu Choices\n");
        printf("------------\n");
        printf("1) Enter a new string\n");
        printf("4) Change all letters to Upper Case\n");
        printf("5) Change all letters to lower case\n");
        printf("8) Quit");
        printf("\nEnter your choices: ");
        scanf("%i", &choices);


        switch(choices)
        {
            case 1:
                //Enter a new String
                readCString(cstr);

                break;

            case 4:
                //Change all letters to Upper Case
                obj = [uppercase uppercaseString];
                NSLog(@"Uppercase conversion: %s", [uppercase UTF8String]);
                break;

            case 5:
                //Change all letters to lower case
                obj = [lowercase lowercaseString];
                NSLog (@"Lowercase conversion: %@", obj);
                break;



            case 8:
                //Quit
                break;
            default:  printf("You entered an invalid choice\n");
                done = TRUE;

        }

    } while (!done);

}
return 0;
}
Was it helpful?

Solution

I think the reason why you are experiencing this issue it because you are NSLoging [uppercase UTF8String] which you never set the the new uppercase value. You should use NSLog(@"Uppercase conversion: %s", [obj UTF8String]); because obj is set to the uppercase conversion, or rename your variables.

So case 4 should look like this:

case 4:
                //Change all letters to Upper Case
                obj = [uppercase uppercaseString];
                NSLog(@"Uppercase conversion: %s", [obj UTF8String]);
                break;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top