为什么函数不返回小写字母?

Why is the function not returning lowercase letters?

我目前是 C 语言的新手,所以我对 Java 的 OOP 背景仍然有些陌生。我正在尝试从终端获取输入,然后将其全部转为小写字母,但该功能似乎无法正常工作。有什么建议吗?

#include <stdio.h>

int lower(int c){
  if (c >= 'A' && c <= 'Z')
    return c + 'a' - 'A';
  else
    return c;
}

int main(){
  int c;
  while ((c = getchar()) != EOF){
    lower(c);
    putchar(c);
  }
}

代码应使用 lower 的 return 值:

putchar(lower(c));

您可能还喜欢使用标准库函数tolower