blob: 44cdde75f1d9ee06c0fb95f2f2cbf5c0cccccce4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include <stdio.h>
/* The C Programming Language: 2nd Edition
*
* Exercise 2-10: Rewrite the function 'lower', which converts upper case
* letters to lower case, with a conditional expression instead of if-else.
*
* Answer: The tertiary ?: operators also _evaluate_, so they can be used in
* a lot of different places.
*/
int lower(int c) {
return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
}
int main() {
char foo = 'F';
printf("The following letter should be lowercase: %c\n", lower(foo));
return 0;
}
|