前言
c语言中常用的字符串处理strlwr函数总结。
一、strlwr函数(大写转小写)使用
使用
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char p1[20] = "HELLO";
printf("转化前:%s\n",p1);
strlwr(p1);
printf("转化后:%s\n",p1);
return 0;
}
执行后打印
转化前:HELLO
转化后:hello
二、实现方法
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void mystrlwr(char *p)
{
while(*p)
{
if('A'<=*p && *p<='Z')
{
*p=*p+'a'-'A';
}
p++;
}
}
int main()
{
char p1[20] = "HELLO";
printf("转化前:%s\n",p1);
mystrlwr(p1);
printf("转化后:%s\n",p1);
return 0;
}
执行
$ gcc strlwr.c -o strlwr -static
$ ./strlwr
转化前:HELLO
转化后:hello