Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        7个月前关闭。
                                                                                            
                
        
如果my_array[50]内部随机包含大写字母,是否有任何方法可以找到它们并将它们切换为小写字母?我真的在寻找一种独立于实现的方法,因为它将成为跨平台的。该代码也将在其他语言上使用。

最佳答案

C提供了tolower函数,该函数将大写字母转换为小写字母,并使其他字符保持不变。它受当前语言环境的影响(根据您使用setlocale函数设置的语言环境,它将使用不同的字母)。它应与unsigned char字符一起使用。

#include <ctype.h>
#include <stdlib.h>

/*  Given length characters starting at p,
    convert uppercase letters to lowercase.
*/
void ToLower(size_t length, unsigned char *p)
{
    for (size_t i = 0; i < length; ++i)
        p[i] = tolower(p[i]);
}


(对于“宽字符”,功能towctrans提供了类似的操作。使用起来更加复杂。)

10-08 08:17
查看更多