C-字符串大小写转换
2022-03-03 本文已影响0人
CocoaJason
void func(char *str, int flag);
int main()
{
char buff[100];
printf("从键盘上输入字符串:");
scanf("%s", buff);
printf("源字符串%s\n", buff);
func(buff, 0);
printf("大写转小写:%s \n", buff);
func(buff, 1);
printf("小写转大写%s \n", buff);
return 0;
}
void func(char *str, int flag)
{
int data;
while (*str != '\0')
{
if (flag)
{
if (*str >= 'a' && *str <= 'z')
{
*str = *str - 32;
}
}
else
{
if (*str >= 'A' && *str <= 'Z')
{
*str = *str + 32;
}
}
str++;
}
}