user12245018
user12245018

Reputation:

Why is the function not returning lowercase letters?

I'm currently new to C so how things work is still slightly alien to me as I come from an OOP background of Java. I'm trying to get an input from the terminal and then turn it into all lowercase letters however it seems the function isn't working. Any tips if possible?

#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);
  }
}

Upvotes: 0

Views: 136

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136425

The code should use the return values of lower:

putchar(lower(c));

You may also like to use the standard library function tolower.

Upvotes: 3

Related Questions