char *strlwr(char *s);
#include <string.h>
非 ANSI/ISO C 標準,屬 Microsoft/Borland 擴展。
將字符串 s 中所有大寫字母轉換為小寫。非字母字符不變。原地修改緩衝區。
返回指向 s 的指針。
// strlwr.c
#include <stdio.h>
#include <string.h>
int main() {
char s[] = "Copywrite 1999-2000 GGV Technologies"; // 必須用數組
printf("原始: %s\n", s);
strlwr(s);
printf("轉換: %s\n", s); // copywrite 1999-2000 ggv technologies
return 0;
}
strupr,傳入 char* 指向常量區會崩潰。LC_CTYPE 影響,多字節編碼環境下行為不可預期。tolower() 循環。
#include <ctype.h>
void my_strlwr(char *s) {
while (*s) { *s = tolower((unsigned char)*s); s++; }
}
strupr:小寫轉大寫(同屬非標準)。tolower/toupper:標準單字符轉換 (ctype.h)。strlwr 是 strupr 的對應函數,同樣非標準、有風險。生產代碼請使用標準 tolower() 循環或 C++ std::transform。