字符串中的字母大小写转换、生成随机字符串
一、字符串中小写字符转为大写
void lowerToupper(char *str) { while(*str) { if(*str >= 'a' && *str <= 'z') { *str -= 32; } str++; } *str = '\0'; }
二、字符串中大写字符转为小写
void upperTolower(char *str) { while(*str) { if(*str >= 'A' && *str <= 'Z') { *str += 32; } str++; } *str = '\0'; }
三、生成随机字符串
const unsigned char allChar[63] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; void generateStr(char *dest, unsigned int len) { unsigned int cnt, randNo; srand((unsigned int)time(NULL)); for(cnt = 0; cnt < len; cnt++) { randNo = rand() % 62; *dest = allChar[randNo]; dest++; } *dest = '\0'; }