【发布时间】:2012-08-27 16:03:25
【问题描述】:
下面的代码 sn-p 用于将字符串转换为小写。
int main()
{
unsigned char s[] = "AbS.d_";
tolower(s);
printf("%s\n", s);
return 0;
}
我得到output 为:
AbS.d_
为什么字符串没有被转换?
【问题讨论】:
下面的代码 sn-p 用于将字符串转换为小写。
int main()
{
unsigned char s[] = "AbS.d_";
tolower(s);
printf("%s\n", s);
return 0;
}
我得到output 为:
AbS.d_
为什么字符串没有被转换?
【问题讨论】:
tolower 接受 int 并返回降低的 int。
这应该可行:
int i=0;
for(i=0; s[i]; i++)
{
s[i]=tolower(s[i]);
}
【讨论】:
for(i=0; s[i]; i++) { ... }吗?
int。
tolower 将字符类型作为参数,但您使用的是字符串。您需要遍历您的数组,并为每个字符调用 tolower。
【讨论】:
tolower的实现是保证免等待的。