Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - Convert an uppercase letter to lowercase

Tags:

c

A really simple program. I just want to turn an 'A' into an 'a', but output is giving me 'A'.

#include <stdio.h>

int main(void) {
    putchar(lower('A')); 

}

lower(a) 
int a; 
{
    if ((a >= 65) && (a >= 90))
        a = a + 32; 
    return a;  
}
like image 224
lche Avatar asked Mar 29 '13 18:03

lche


1 Answers

You messed up the second part of your if condition. That should be a <= 90.

Also, FYI, there is a C library function tolower that does this already:

#include <ctype.h>
#include <stdio.h>

int main() {
    putchar(tolower('A'));
}
like image 61
Scott Olson Avatar answered Oct 19 '22 14:10

Scott Olson