1 00:00:00,000 --> 00:00:00,650 2 00:00:00,650 --> 00:00:02,410 >> DAVID MALAN: Let's now refine this program a bit. 3 00:00:02,410 --> 00:00:05,940 Wouldn't it be nice if there were a function called, say, islower that 4 00:00:05,940 --> 00:00:08,210 could return true or false based on whether a given 5 00:00:08,210 --> 00:00:09,780 character is lowercase? 6 00:00:09,780 --> 00:00:12,920 Wouldn't it be even nicer if there were a function called toupper that 7 00:00:12,920 --> 00:00:15,540 could convert a lowercase letter to uppercase? 8 00:00:15,540 --> 00:00:18,790 >> Well, it turns out that both functions exist, and they're declared in a file 9 00:00:18,790 --> 00:00:20,660 called ctype.h. 10 00:00:20,660 --> 00:00:23,540 So let's add that file to my includes. 11 00:00:23,540 --> 00:00:26,450 include ctype.h. 12 00:00:26,450 --> 00:00:30,135 And now let's utilize both of those functions, replacing first my if 13 00:00:30,135 --> 00:00:33,270 condition as follows. 14 00:00:33,270 --> 00:00:40,530 if islower s bracket i, thereby returning true or false if the ith 15 00:00:40,530 --> 00:00:42,930 character in s is a lower case letter. 16 00:00:42,930 --> 00:00:49,270 And let's now replace my arithmetic expression here with simply toupper of 17 00:00:49,270 --> 00:00:53,860 s bracket i, thereby returning the uppercase equivalent of the ith 18 00:00:53,860 --> 00:00:56,470 character in s if it's lower case. 19 00:00:56,470 --> 00:00:59,270 >> I'm going to leave my else block alone, because if the letter is not 20 00:00:59,270 --> 00:01:01,760 lowercase, I still want to print it out unchanged. 21 00:01:01,760 --> 00:01:03,900 And let's now compile this program. 22 00:01:03,900 --> 00:01:06,860 Make [? capitalize1. ?] 23 00:01:06,860 --> 00:01:10,020 Let's now run the program with capitalize1. 24 00:01:10,020 --> 00:01:12,870 And let's now type a word like hello in all lowercase. 25 00:01:12,870 --> 00:01:17,240 H-E-L-L-O, Enter, and it indeed prints in all uppercase. 26 00:01:17,240 --> 00:01:20,910 >> Let's try one more scenario, though, this time inputting my own name with 27 00:01:20,910 --> 00:01:24,240 the first letter, D, capitalized already, just in case I messed 28 00:01:24,240 --> 00:01:27,430 something up in my own code with the capitalization of that char. 29 00:01:27,430 --> 00:01:31,250 Enter, but no, DAVID in all caps prints this time as expected. 30 00:01:31,250 --> 00:01:34,365