我已经编写了这个函数来将预设的小写字符串转换为它的大写变体。我已经尝试了我所知道的每种不同的配置,这些配置将小写转换为大写,但是当我打印它时。它仍然以小写结尾。所以我有点卡住了。
char* stoupper(char str[]);
char str[100]= "uppercase";
printf("%s" , stoupper(str)); // Test to make sure it is working
char* stoupper(char str[])
{
int i = 0;
while(str[i] != '\0')
{
if(str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + ('A' - 'a');
i++;
}
return str;
}
/* I've tried various variations of this function this is just the one i had first */ 发布于 2013-04-16 07:50:16
我认为你的if条件应该是:
if(str[i] >= 'a' && str[i] <= 'z') https://stackoverflow.com/questions/16026457
复制相似问题