1 00:00:00,000 --> 00:00:00,190 2 00:00:00,190 --> 00:00:03,310 >> SPEAKER: Let's write a program that tries to copy two strings. 3 00:00:03,310 --> 00:00:07,690 I've already gotten started by first printing out "Say something." I next 4 00:00:07,690 --> 00:00:10,130 call GetString, storing the return value in s. 5 00:00:10,130 --> 00:00:12,800 And then I make sure that s is not null. 6 00:00:12,800 --> 00:00:16,860 >> Let's next make our copy of S. I'm going to declare a new variable, t, 7 00:00:16,860 --> 00:00:18,860 and store in it s. 8 00:00:18,860 --> 00:00:21,740 I'm next going to claim, with printf, that I'm going to 9 00:00:21,740 --> 00:00:24,410 capitalize that copy. 10 00:00:24,410 --> 00:00:28,690 I'm next going to check that t is at least greater than 0 in length so that 11 00:00:28,690 --> 00:00:31,800 I don't accidentally try to capitalize a letter that's not there. 12 00:00:31,800 --> 00:00:36,670 Once I'm sure, I'm going to change the value at t bracket 0 to be the return 13 00:00:36,670 --> 00:00:40,290 value of toupper, a function that converts its input to uppercase, 14 00:00:40,290 --> 00:00:43,820 passing in as its input t bracket 0. 15 00:00:43,820 --> 00:00:49,650 >> Lastly, I'm going to print out what the original value was, which, of 16 00:00:49,650 --> 00:00:51,650 course, was s. 17 00:00:51,650 --> 00:00:58,950 And then I'm going to print what the value of the copy is, which is t. 18 00:00:58,950 --> 00:01:02,820 >> When I now compile and run this program, I hope to see my original 19 00:01:02,820 --> 00:01:06,430 input followed by a copy thereof with only the copy capitalized. 20 00:01:06,430 --> 00:01:08,260 But let's check. 21 00:01:08,260 --> 00:01:12,630 Make copy 0, ./ copy 0. 22 00:01:12,630 --> 00:01:16,100 And I'll provide an input of, say, hello, but in all lowercase, 23 00:01:16,100 --> 00:01:17,620 and then hit Enter. 24 00:01:17,620 --> 00:01:21,680 >> Unfortunately, it seems that both the original and the copy are now "Hello" 25 00:01:21,680 --> 00:01:24,680 with a capital H. But that's clearly not what I typed. 26 00:01:24,680 --> 00:01:29,240 So apparently, when I capitalized t, I somehow capitalized s, even though I 27 00:01:29,240 --> 00:01:32,860 thought I was making a copy of s and calling it t. 28 00:01:32,860 --> 00:01:34,520 Surely, something here is wrong. 29 00:01:34,520 --> 00:01:35,770 But how can we fix? 30 00:01:35,770 --> 00:01:36,640