基本上这是一个开关案例菜单程序。我在菜单部分之前输入了一个字符串函数来保持它的有序性。我目前的主要问题是案例4.我要做的是创建一个将整个字符串转换为大写的函数。但我似乎找不到将其应用于输入字符串的方法。它仅在我定义预定字符串时才有效。
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;
}
答案 0 :(得分:0)
我认为您遇到此问题的原因是因为您是NSLoging [uppercase UTF8String]
,您永远不会设置新的大写值。您应该使用NSLog(@"Uppercase conversion: %s", [obj UTF8String]);
,因为obj设置为大写转换,或重命名变量。
所以案例4应该是这样的:
case 4:
//Change all letters to Upper Case
obj = [uppercase uppercaseString];
NSLog(@"Uppercase conversion: %s", [obj UTF8String]);
break;