1 00:00:00,000 --> 00:00:05,410 2 00:00:05,410 --> 00:00:08,770 >> ANDI PENG: We are almost through all the psets. 3 00:00:08,770 --> 00:00:12,080 In fact, we're through the majority of the most difficult psets. 4 00:00:12,080 --> 00:00:14,350 So we're actually just going to kind of breeze 5 00:00:14,350 --> 00:00:16,050 through the next couple of weeks. 6 00:00:16,050 --> 00:00:19,520 >> We're going to start talking about our final projects, the events coming up 7 00:00:19,520 --> 00:00:21,320 in the next few weeks. 8 00:00:21,320 --> 00:00:23,825 And life will be a breeze. 9 00:00:23,825 --> 00:00:26,510 10 00:00:26,510 --> 00:00:27,680 So not too much today. 11 00:00:27,680 --> 00:00:30,280 >> Hopefully, will actually breeze through the agenda for today, 12 00:00:30,280 --> 00:00:33,400 and then be out of here with some time to spare. 13 00:00:33,400 --> 00:00:36,210 Also, I want to apologize for the lack of candy today. 14 00:00:36,210 --> 00:00:37,030 I don't know why. 15 00:00:37,030 --> 00:00:40,520 But in the week leading up Halloween, I would forget candy. 16 00:00:40,520 --> 00:00:43,290 >> So I'm actually just a vast disappointment to you right now. 17 00:00:43,290 --> 00:00:47,050 Because I literally remember candy for every single class, but Halloween. 18 00:00:47,050 --> 00:00:49,345 But next week, I will bring double the amount of candy 19 00:00:49,345 --> 00:00:50,720 to make up for that, all for you. 20 00:00:50,720 --> 00:00:53,260 It'll be great. 21 00:00:53,260 --> 00:00:56,690 >> So I have a couple of announcements regarding some scheduling. 22 00:00:56,690 --> 00:00:59,520 I have some scheduling issues. 23 00:00:59,520 --> 00:01:02,150 Then we're going to move on to talk about what's called chmod. 24 00:01:02,150 --> 00:01:05,980 We're going to talk about quickly TCP/IP HTTP. 25 00:01:05,980 --> 00:01:09,770 >> And then we're going to code our own website using HTML and CSS. 26 00:01:09,770 --> 00:01:13,030 And then I'll actually leave maybe like 20 minutes to talk about pset6. 27 00:01:13,030 --> 00:01:16,550 Because pset6 is actually a lot of stuff that we've already seen before, 28 00:01:16,550 --> 00:01:19,090 but I wanted to refresh some of those concepts 29 00:01:19,090 --> 00:01:22,140 as well as teach a couple new functions. 30 00:01:22,140 --> 00:01:23,110 >> Cool. 31 00:01:23,110 --> 00:01:25,440 So first of all, welcome back from break. 32 00:01:25,440 --> 00:01:27,410 I hope you're break was enjoyable. 33 00:01:27,410 --> 00:01:29,695 Would did you do for break? 34 00:01:29,695 --> 00:01:30,820 AUDIENCE: Went to New York. 35 00:01:30,820 --> 00:01:32,030 ANDI PENG: You went to New York? 36 00:01:32,030 --> 00:01:33,738 I think half our school went to New York. 37 00:01:33,738 --> 00:01:34,740 It's all right. 38 00:01:34,740 --> 00:01:38,250 I spent most of my break sedentary in bed Netflixing. 39 00:01:38,250 --> 00:01:39,760 And it was a good time. 40 00:01:39,760 --> 00:01:43,450 >> But we are now back, back in session, back in the swing of things. 41 00:01:43,450 --> 00:01:47,900 We have a pset due this Friday at noon. 42 00:01:47,900 --> 00:01:50,240 >> I think you've already picked up your quiz, yeah? 43 00:01:50,240 --> 00:01:52,140 So anyone else who has not had their quizzes, 44 00:01:52,140 --> 00:01:55,416 please come and get your quizzes from me at the end of the section. 45 00:01:55,416 --> 00:01:56,540 Or track me down on campus. 46 00:01:56,540 --> 00:01:59,310 I'll have it with me somewhere. 47 00:01:59,310 --> 00:02:02,120 >> Our final project pre-proposal also. 48 00:02:02,120 --> 00:02:06,380 So for those of us who have never taken this class before, the capstone of CS50 49 00:02:06,380 --> 00:02:11,150 is very much culminated in this grand project that students propose. 50 00:02:11,150 --> 00:02:14,300 And the pre-proposal, just a general idea 51 00:02:14,300 --> 00:02:18,500 of what one might want to do for their project, that idea is due Monday, 52 00:02:18,500 --> 00:02:20,780 next Monday at noon. 53 00:02:20,780 --> 00:02:23,800 >> So pretty much, David I think will talk more about this in lecture 54 00:02:23,800 --> 00:02:25,390 if he hasn't already. 55 00:02:25,390 --> 00:02:28,710 And there's a solid page on our website explaining 56 00:02:28,710 --> 00:02:31,610 all the requirements of the project. 57 00:02:31,610 --> 00:02:34,082 But essentially, pick any topic that you've 58 00:02:34,082 --> 00:02:35,915 been interested in throughout your time here 59 00:02:35,915 --> 00:02:41,760 at CS, whether it be gaming or design or video or anything. 60 00:02:41,760 --> 00:02:44,920 >> And you can really kind of now apply some of the lessons 61 00:02:44,920 --> 00:02:52,470 that we've learned here in CS50-- hi, welcome-- to pretty much conducting 62 00:02:52,470 --> 00:02:56,320 a final project of your choice. 63 00:02:56,320 --> 00:02:59,570 All that's due Monday is just a brief blurb via email 64 00:02:59,570 --> 00:03:02,010 to me, a quick sentence, like, hey, Andi, 65 00:03:02,010 --> 00:03:06,490 I'm really interested in designing a game that does this for iOS. 66 00:03:06,490 --> 00:03:07,420 Cool. 67 00:03:07,420 --> 00:03:10,767 Just let me your brief initial ideas for your final projects. 68 00:03:10,767 --> 00:03:13,850 And we'll talk through whether or not that is actually a good idea or not, 69 00:03:13,850 --> 00:03:15,590 if it's a feasible idea or not. 70 00:03:15,590 --> 00:03:20,760 But just the pre-proposal is due next Monday. 71 00:03:20,760 --> 00:03:24,190 pset6, our lovely web-- that is wrong. 72 00:03:24,190 --> 00:03:25,060 Pset7? 73 00:03:25,060 --> 00:03:25,560 pset6? 74 00:03:25,560 --> 00:03:26,680 It's pset6, right? 75 00:03:26,680 --> 00:03:32,690 >> pset6, our web server, is due Friday at noon with the late day. 76 00:03:32,690 --> 00:03:37,660 Office hours resume normally from Monday to Thursday 8:00 to 11:00 this week. 77 00:03:37,660 --> 00:03:39,710 I think Commons for the next three nights. 78 00:03:39,710 --> 00:03:40,310 Cool. 79 00:03:40,310 --> 00:03:44,260 Before we had into material, does anyone have any questions, jokes, stories? 80 00:03:44,260 --> 00:03:46,662 What did you do for fall break? 81 00:03:46,662 --> 00:03:48,640 >> AUDIENCE: What I do? 82 00:03:48,640 --> 00:03:52,834 >> ANDI PENG: Already it's ages ago actually. 83 00:03:52,834 --> 00:03:54,000 Christabel went to New York. 84 00:03:54,000 --> 00:03:55,614 I stayed here and Netflixed. 85 00:03:55,614 --> 00:03:56,864 AUDIENCE: Oh, yeah I was here. 86 00:03:56,864 --> 00:03:57,614 ANDI PENG: Oh, OK. 87 00:03:57,614 --> 00:03:59,792 AUDIENCE: I don't remember what specifically. 88 00:03:59,792 --> 00:04:00,710 ANDI PENG: That's OK. 89 00:04:00,710 --> 00:04:01,960 AUDIENCE: Netflixing probably. 90 00:04:01,960 --> 00:04:02,990 ANDI PENG: Netflixing. 91 00:04:02,990 --> 00:04:04,710 Yeah, it's a good time. 92 00:04:04,710 --> 00:04:05,780 OK. 93 00:04:05,780 --> 00:04:06,340 All right. 94 00:04:06,340 --> 00:04:08,877 Any questions before we jump into material? 95 00:04:08,877 --> 00:04:11,210 Also, we're going to try to speed through section today, 96 00:04:11,210 --> 00:04:12,504 not too much to cover. 97 00:04:12,504 --> 00:04:14,420 And hopefully, we'll get out here a bit early. 98 00:04:14,420 --> 00:04:15,580 Sorry for not candy, also. 99 00:04:15,580 --> 00:04:20,310 I'm a disappointment, especially during Halloween. 100 00:04:20,310 --> 00:04:21,110 >> All right. 101 00:04:21,110 --> 00:04:21,810 Cool. 102 00:04:21,810 --> 00:04:28,370 So we're going to start talking about a command line argument called chmod. 103 00:04:28,370 --> 00:04:32,850 chmod, all it is is just a Unix system call conducted from the command line 104 00:04:32,850 --> 00:04:34,700 to change file permissions. 105 00:04:34,700 --> 00:04:37,790 So for example, we've all encountered a page 106 00:04:37,790 --> 00:04:40,550 like this probably sometime in our life span of being an internet 107 00:04:40,550 --> 00:04:45,110 user, where our web server has given us the error of Forbidden. 108 00:04:45,110 --> 00:04:49,086 You don't have permission to access, yadda, yadda, yadda, on this server. 109 00:04:49,086 --> 00:04:50,960 All that really means is that the permissions 110 00:04:50,960 --> 00:04:53,920 that were attached to whatever page you were trying to access 111 00:04:53,920 --> 00:04:55,840 were not open to you. 112 00:04:55,840 --> 00:04:57,870 So pretty much, chmod is the way in which 113 00:04:57,870 --> 00:05:02,140 we can modify those system permissions to give everyone, the user, the group, 114 00:05:02,140 --> 00:05:04,975 or the world, or any combination of those access 115 00:05:04,975 --> 00:05:07,900 to certain files, directories, anything really, 116 00:05:07,900 --> 00:05:11,720 any sort of system on an operating system. 117 00:05:11,720 --> 00:05:14,039 So if any of guys have computers if you feel 118 00:05:14,039 --> 00:05:17,080 like following along with me today, totally feel free to just type things 119 00:05:17,080 --> 00:05:17,580 in. 120 00:05:17,580 --> 00:05:19,790 If not, you can just hang out. 121 00:05:19,790 --> 00:05:23,170 So I'm going to actually pull up my terminal right now. 122 00:05:23,170 --> 00:05:29,810 123 00:05:29,810 --> 00:05:32,310 >> So the command to run chmod, or at least just 124 00:05:32,310 --> 00:05:37,840 to list the permissions of your file directory, is just ls-l. 125 00:05:37,840 --> 00:05:42,270 As you can see, a bunch of stuff pops up most of which 126 00:05:42,270 --> 00:05:45,390 is important to us on the left-hand side here. 127 00:05:45,390 --> 00:05:48,710 You guys see a bunch of rs, ws, 1/. 128 00:05:48,710 --> 00:05:49,210 Yeah. 129 00:05:49,210 --> 00:05:51,400 >> Those are essentially just all the file permissions 130 00:05:51,400 --> 00:05:55,960 to explain what certain directories and files within your system have. 131 00:05:55,960 --> 00:05:58,150 So let's go back to the power point here. 132 00:05:58,150 --> 00:06:02,450 133 00:06:02,450 --> 00:06:06,500 So in addition to the file names as you guys can see on the right, 134 00:06:06,500 --> 00:06:10,312 we are looking to see essentially just the column on the left. 135 00:06:10,312 --> 00:06:12,020 So in addition to just the file names, we 136 00:06:12,020 --> 00:06:16,240 can see the permissions of files, their owner group, the group name, the date 137 00:06:16,240 --> 00:06:18,460 that the file was last modified, et cetera. 138 00:06:18,460 --> 00:06:20,640 You can see a lot of things using chmod. 139 00:06:20,640 --> 00:06:26,037 So the way that we read chmod is that the first letter we pretty much ignore 140 00:06:26,037 --> 00:06:27,370 in terms of reading permissions. 141 00:06:27,370 --> 00:06:31,460 >> The first letter just tells us what type of system we're accessing. 142 00:06:31,460 --> 00:06:34,240 d, in this case, is a folder or directory. 143 00:06:34,240 --> 00:06:38,430 So we know that currently my workspace section seven was a directory. 144 00:06:38,430 --> 00:06:41,530 And then you see three triads, essentially just 145 00:06:41,530 --> 00:06:43,490 three sets of three characters. 146 00:06:43,490 --> 00:06:45,680 And you can think of each as a bit. 147 00:06:45,680 --> 00:06:49,260 >> So you just have three sets of three bits, nine bits in total. 148 00:06:49,260 --> 00:06:51,420 You treat them in groups of three. 149 00:06:51,420 --> 00:06:56,230 So the first group of three is always your user permissions. 150 00:06:56,230 --> 00:07:00,557 >> Your second group of three is always your group permissions. 151 00:07:00,557 --> 00:07:02,765 And your third set of three is always like the world, 152 00:07:02,765 --> 00:07:04,380 the everywhere permissions. 153 00:07:04,380 --> 00:07:06,320 So I guess the easy question to ask is what is 154 00:07:06,320 --> 00:07:08,051 the difference between user and group. 155 00:07:08,051 --> 00:07:09,800 The main difference between user and group 156 00:07:09,800 --> 00:07:13,180 is that a user is just you personally accessing whatever it is right now. 157 00:07:13,180 --> 00:07:18,070 A group can be if you have multiple users on one computer, for example. 158 00:07:18,070 --> 00:07:20,280 All of them can be treated as a group. 159 00:07:20,280 --> 00:07:23,220 >> And then the world is just the world, everyone. 160 00:07:23,220 --> 00:07:31,010 So we can see later on how we can modify those into different permissions. 161 00:07:31,010 --> 00:07:33,080 So pretty much, we're going to still focus 162 00:07:33,080 --> 00:07:38,450 on the part on the left, where for directory CS50 we see drwx, 163 00:07:38,450 --> 00:07:40,970 where the r just means it's readable. 164 00:07:40,970 --> 00:07:42,620 >> The w just means it's writable. 165 00:07:42,620 --> 00:07:45,470 And then the x just means it's executable. 166 00:07:45,470 --> 00:07:47,220 You'd think it kind of doesn't make sense. 167 00:07:47,220 --> 00:07:47,993 It should be e. 168 00:07:47,993 --> 00:07:50,150 But x actually kind of works a little better, 169 00:07:50,150 --> 00:07:51,690 because you can remember it better. 170 00:07:51,690 --> 00:07:56,406 >> So the three types of things you can do, you can either read a file, 171 00:07:56,406 --> 00:07:59,280 you can have permission to write a file, or you could have permission 172 00:07:59,280 --> 00:08:00,780 to execute a file. 173 00:08:00,780 --> 00:08:04,580 And so the way that we actually represent those in bits 174 00:08:04,580 --> 00:08:06,940 is the numbers 4, 2, and 1. 175 00:08:06,940 --> 00:08:12,870 So anything that's readable is represented by the number of 4. 176 00:08:12,870 --> 00:08:15,150 >> Anything that's writable is represented by 2. 177 00:08:15,150 --> 00:08:18,880 And anything that's executable as represented by 1. 178 00:08:18,880 --> 00:08:22,860 So in this sense, we can also represent these numbers-- 179 00:08:22,860 --> 00:08:25,281 hi, welcome, in a different way. 180 00:08:25,281 --> 00:08:25,780 Sorry. 181 00:08:25,780 --> 00:08:28,510 Before everyone, I'm going to apologize on behalf of everyone 182 00:08:28,510 --> 00:08:29,468 entering the class now. 183 00:08:29,468 --> 00:08:30,810 I forgot candy today. 184 00:08:30,810 --> 00:08:33,640 I'm sorry I'm a failure this week of Halloween. 185 00:08:33,640 --> 00:08:37,070 I will bring double the amount of candy next time to make up for it. 186 00:08:37,070 --> 00:08:42,360 But anyways, sorry about that guys, sorry. 187 00:08:42,360 --> 00:08:46,640 >> So the way that we can actually input on our command the argument is we 188 00:08:46,640 --> 00:08:51,760 can do chmod group slash permissions, where the group is just whatever 189 00:08:51,760 --> 00:08:54,130 group we're trying to change. 190 00:08:54,130 --> 00:08:56,600 And the permissions are whatever we want to add to it. 191 00:08:56,600 --> 00:08:58,860 So for example, the plus adds permissions, 192 00:08:58,860 --> 00:09:01,590 and the subtract takes away permissions. 193 00:09:01,590 --> 00:09:07,060 >> And the types of group we have our a for all, u for users, g for groups, 194 00:09:07,060 --> 00:09:09,050 or o for others. 195 00:09:09,050 --> 00:09:10,300 It's a bit abstract right now. 196 00:09:10,300 --> 00:09:13,550 But we'll go over a couple examples just to demonstrate this real quick. 197 00:09:13,550 --> 00:09:16,960 Everyone good on this slide, so I can move on? 198 00:09:16,960 --> 00:09:18,280 Cool. 199 00:09:18,280 --> 00:09:21,290 >> So for example, rwx. 200 00:09:21,290 --> 00:09:26,720 Before we talk about what it represents, first of all what does rwx mean? 201 00:09:26,720 --> 00:09:31,450 If you see that this certain file has permissions of rwx, 202 00:09:31,450 --> 00:09:34,270 what does that mean the person could be able to do? 203 00:09:34,270 --> 00:09:35,740 >> AUDIENCE: Read, write and execute. 204 00:09:35,740 --> 00:09:36,420 >> ANDI PENG: Yeah, exactly. 205 00:09:36,420 --> 00:09:37,840 You can read write and execute. 206 00:09:37,840 --> 00:09:40,790 Because all three of those characters are present. 207 00:09:40,790 --> 00:09:44,370 So if we go ahead and talk about this in terms of bits, 208 00:09:44,370 --> 00:09:48,490 the rwx can also be represented as 700. 209 00:09:48,490 --> 00:09:53,370 Because as you can see in any sort of file directory permission, 210 00:09:53,370 --> 00:09:54,320 there's three triads. 211 00:09:54,320 --> 00:09:58,060 >> In this case, only the first triad has anything there. 212 00:09:58,060 --> 00:10:04,050 So in this case, the r is 4, the w is 2, and the x is 1. 213 00:10:04,050 --> 00:10:05,860 If you add those together, it's 7. 214 00:10:05,860 --> 00:10:08,730 >> And so if you convert it to binary, it's 700. 215 00:10:08,730 --> 00:10:10,310 Because 7 is the first triad. 216 00:10:10,310 --> 00:10:12,760 0, there's nothing present in the second triad. 217 00:10:12,760 --> 00:10:15,850 And then there's nothing present in the third triad, so that's another 0. 218 00:10:15,850 --> 00:10:22,520 >> So in the same sense, a bunch of triads can be represented just in bits, just 219 00:10:22,520 --> 00:10:23,600 in binary as well. 220 00:10:23,600 --> 00:10:29,920 So 700 means the exact same thing as rwx------ in terms of permissions. 221 00:10:29,920 --> 00:10:32,590 Everyone clear on that? 222 00:10:32,590 --> 00:10:33,090 Cool. 223 00:10:33,090 --> 00:10:40,290 And so chmod 111 would give which permissions to the file? 224 00:10:40,290 --> 00:10:42,600 Give you guys a couple seconds to convert this. 225 00:10:42,600 --> 00:10:51,140 226 00:10:51,140 --> 00:10:53,250 Remember, the first triad is for the user. 227 00:10:53,250 --> 00:10:56,320 The second triad is for the group. 228 00:10:56,320 --> 00:10:59,450 And the third triad is for everyone. 229 00:10:59,450 --> 00:11:03,680 >> And so chmod 111 would give which type of permissions and to whom? 230 00:11:03,680 --> 00:11:06,520 231 00:11:06,520 --> 00:11:09,020 Take a couple seconds to think about it and come back. 232 00:11:09,020 --> 00:11:19,790 233 00:11:19,790 --> 00:11:20,910 Yeah. 234 00:11:20,910 --> 00:11:22,920 >> AUDIENCE: So everyone can execute it. 235 00:11:22,920 --> 00:11:23,920 ANDI PENG: Yup, exactly. 236 00:11:23,920 --> 00:11:25,544 AUDIENCE: But nobody can read or write. 237 00:11:25,544 --> 00:11:27,910 ANDI PENG: And feel free to explain to everyone 238 00:11:27,910 --> 00:11:29,860 how you came to that conclusion. 239 00:11:29,860 --> 00:11:34,290 >> AUDIENCE: Well, for the user, the group, and the world, it's all 1, 240 00:11:34,290 --> 00:11:35,700 which is the code for executable. 241 00:11:35,700 --> 00:11:37,070 >> ANDI PENG: Yeah, exactly. 242 00:11:37,070 --> 00:11:42,320 So 1, in this case, all we know is that that is the executable code. 243 00:11:42,320 --> 00:11:45,280 Because reading is 4. 244 00:11:45,280 --> 00:11:45,990 Writing is 2. 245 00:11:45,990 --> 00:11:47,230 And the executable is 1. 246 00:11:47,230 --> 00:11:51,580 So is all three triads are 1, that means that to the world, to the user, 247 00:11:51,580 --> 00:11:54,680 and to the group, they are all executable. 248 00:11:54,680 --> 00:11:56,170 >> Everyone good with that? 249 00:11:56,170 --> 00:11:56,940 OK. 250 00:11:56,940 --> 00:11:59,180 And so the second way that we can actually 251 00:11:59,180 --> 00:12:01,220 write this also is you could just do chmod 252 00:12:01,220 --> 00:12:05,050 a plus x. a means all or everyone. 253 00:12:05,050 --> 00:12:07,060 The plus means giving permissions to. 254 00:12:07,060 --> 00:12:09,112 And then the x means executable. 255 00:12:09,112 --> 00:12:11,070 So there's two commands are actually identical. 256 00:12:11,070 --> 00:12:12,903 So if you want to run this in your terminal, 257 00:12:12,903 --> 00:12:15,830 you do chmod 111, name of your directory or your file. 258 00:12:15,830 --> 00:12:18,520 Or you can do chmod a plus x, name of your directory file. 259 00:12:18,520 --> 00:12:22,150 Same thing, just an easier way, perhaps, for some to represent or change 260 00:12:22,150 --> 00:12:24,280 file permissions. 261 00:12:24,280 --> 00:12:28,806 >> Every one OK with chmod before we move on? 262 00:12:28,806 --> 00:12:31,700 Cool. 263 00:12:31,700 --> 00:12:35,336 So now we're going to head into a few slides of very abstract concepts 264 00:12:35,336 --> 00:12:37,210 that I'm pretty much going to breeze through. 265 00:12:37,210 --> 00:12:39,530 And it's totally OK if you don't understand everything. 266 00:12:39,530 --> 00:12:42,330 >> Even now, I still don't really understand everything completely. 267 00:12:42,330 --> 00:12:44,640 But it's more of getting the top level understanding 268 00:12:44,640 --> 00:12:47,280 of how some of these things work. 269 00:12:47,280 --> 00:12:50,490 So we're going to talk quickly about TCP/IP, 270 00:12:50,490 --> 00:12:54,880 which is just Transmission Control Protocol slash Internet Protocol. 271 00:12:54,880 --> 00:12:57,135 >> Recall from lecture, David, did he teach you 272 00:12:57,135 --> 00:13:00,700 the example where he'd pass the notes in an envelope 273 00:13:00,700 --> 00:13:02,790 up to like the top of the lecture hall? 274 00:13:02,790 --> 00:13:06,990 So in the law school auditorium David demonstrated essentially 275 00:13:06,990 --> 00:13:10,370 how TCP/IP works in the sense that all it 276 00:13:10,370 --> 00:13:14,300 is is a means of ensuring that data has been delivered across a server 277 00:13:14,300 --> 00:13:15,870 or on the internet. 278 00:13:15,870 --> 00:13:22,270 So in the example of the envelope and the message, the user at the end 279 00:13:22,270 --> 00:13:26,410 could see that, oh, I needed to receive four packets of information. 280 00:13:26,410 --> 00:13:28,096 >> But I actually only received three. 281 00:13:28,096 --> 00:13:29,470 That means I must be missing one. 282 00:13:29,470 --> 00:13:30,760 And one wasn't delivered. 283 00:13:30,760 --> 00:13:33,990 And so TCP/IP on the internet, through your computer and the server, 284 00:13:33,990 --> 00:13:35,500 does the exact same thing. 285 00:13:35,500 --> 00:13:38,900 All it does is specify a framework in which a lost data 286 00:13:38,900 --> 00:13:41,100 packets can be resent and received. 287 00:13:41,100 --> 00:13:44,760 >> Like on the internet when you're trying to access files online or send files 288 00:13:44,760 --> 00:13:48,210 to your friend or look at web browsers, thousands and thousands 289 00:13:48,210 --> 00:13:50,440 of billions and billions of bytes information 290 00:13:50,440 --> 00:13:52,840 are transferred per millisecond. 291 00:13:52,840 --> 00:13:54,560 And it's really, really confusing. 292 00:13:54,560 --> 00:13:57,110 And it's really hard to actually know what's been sent 293 00:13:57,110 --> 00:13:58,270 and what's not been sent. 294 00:13:58,270 --> 00:14:02,210 >> And so TCP/IP just specifies a cohesive framework 295 00:14:02,210 --> 00:14:04,115 in which your web browser and your server 296 00:14:04,115 --> 00:14:05,990 can kind of communicate with each other, just 297 00:14:05,990 --> 00:14:08,550 make sure that packets are all here and nothing's lost 298 00:14:08,550 --> 00:14:12,700 and all the data that you requested is actually displaying properly. 299 00:14:12,700 --> 00:14:16,350 Everyone OK on just that very brief high level understand? 300 00:14:16,350 --> 00:14:18,510 Cool. 301 00:14:18,510 --> 00:14:21,550 >> So then we're going to move into talking about HTTP, which 302 00:14:21,550 --> 00:14:24,610 is just Hypertext Transfer Protocol. 303 00:14:24,610 --> 00:14:32,550 HTTP, all it is is whatever any page or file is accessed on your website, 304 00:14:32,550 --> 00:14:35,810 the server returns an HTTP status code in response 305 00:14:35,810 --> 00:14:39,869 to the request making sure that either, oh, this request went through. 306 00:14:39,869 --> 00:14:41,410 And everything's displaying properly. 307 00:14:41,410 --> 00:14:43,500 Or, oh, no, 404. 308 00:14:43,500 --> 00:14:44,730 Something went wrong. 309 00:14:44,730 --> 00:14:45,940 Oh, I can't display. 310 00:14:45,940 --> 00:14:50,370 >> All it is is that whatever you're trying to access, 311 00:14:50,370 --> 00:14:55,160 use as the user is trying to access, on the internet-- just making sure 312 00:14:55,160 --> 00:15:00,080 that you either have successfully accessed whatever it was or not 313 00:15:00,080 --> 00:15:02,080 successfully accessed whatever it was. 314 00:15:02,080 --> 00:15:05,120 And so the HTTP status code just provides you 315 00:15:05,120 --> 00:15:09,910 a means of being able to know whether or not it was successful or not. 316 00:15:09,910 --> 00:15:13,440 So for example, an example request. 317 00:15:13,440 --> 00:15:16,050 >> You can see here it's usually typically four lines. 318 00:15:16,050 --> 00:15:22,530 We have a GET HTTP 1.1, which is just the method request URL, the protocol 319 00:15:22,530 --> 00:15:24,490 version, the field name, and the field value. 320 00:15:24,490 --> 00:15:26,810 So no need to completely memorize anything here. 321 00:15:26,810 --> 00:15:29,960 Just kind of familiarize yourself with how these look. 322 00:15:29,960 --> 00:15:34,060 >> In this example, the method request URL is just whatever request 323 00:15:34,060 --> 00:15:35,620 you are sending the server. 324 00:15:35,620 --> 00:15:40,710 Like, hey, server, I really want to access yadda, yadda, yadda, HTTP page. 325 00:15:40,710 --> 00:15:43,785 The protocol version is just whatever version your host or your server 326 00:15:43,785 --> 00:15:45,490 is using to access information. 327 00:15:45,490 --> 00:15:49,510 >> The field name is the website or the URL that you're trying to access, 328 00:15:49,510 --> 00:15:52,610 in this case, www.apple.com. 329 00:15:52,610 --> 00:15:56,110 And the field value is just typically name, value. 330 00:15:56,110 --> 00:15:59,540 And it can be any sort of combination of letters or numbers or whatever. 331 00:15:59,540 --> 00:16:02,890 >> So a typical request, so what your computer actually 332 00:16:02,890 --> 00:16:08,400 sends to the server that says, hey, you know what I need this displayed, 333 00:16:08,400 --> 00:16:13,000 that's the kind of request that they actually receive. 334 00:16:13,000 --> 00:16:16,760 An example response of what the server would send back to you 335 00:16:16,760 --> 00:16:20,320 would be pretty much the same thing, except with a status code at the top. 336 00:16:20,320 --> 00:16:24,550 So 200, 2 0 0 is always the status code for OK. 337 00:16:24,550 --> 00:16:26,050 Like, OK, this request went through. 338 00:16:26,050 --> 00:16:27,980 You were able to access everything correctly. 339 00:16:27,980 --> 00:16:28,810 Life is good. 340 00:16:28,810 --> 00:16:29,990 Life is fine. 341 00:16:29,990 --> 00:16:32,150 Everything is totally good. 342 00:16:32,150 --> 00:16:36,050 >> And so this just tells your browser and your server, hey, everything's good. 343 00:16:36,050 --> 00:16:37,470 I got all the information I need. 344 00:16:37,470 --> 00:16:39,160 Cool. 345 00:16:39,160 --> 00:16:41,790 But the problem is sometimes problems come up 346 00:16:41,790 --> 00:16:46,850 when you have-- last I think I talked about duplicates. 347 00:16:46,850 --> 00:16:48,870 You have less good responses. 348 00:16:48,870 --> 00:16:52,660 >> So for example, 404 is the Page Not Found. 349 00:16:52,660 --> 00:16:54,897 You sometimes have a Forbidden access. 350 00:16:54,897 --> 00:16:56,730 You have various other status codes that I'm 351 00:16:56,730 --> 00:16:59,688 sure you've all seen when you're trying to do research on the internet. 352 00:16:59,688 --> 00:17:02,300 And your browser gives you the, no, cannot access. 353 00:17:02,300 --> 00:17:04,190 And you're like, well, crap. 354 00:17:04,190 --> 00:17:09,260 >> So just pretty much, there's some pretty common status codes. 355 00:17:09,260 --> 00:17:14,109 Maybe familiarize yourself with which ones those are. 356 00:17:14,109 --> 00:17:16,000 The funniest one that I think I've ever heard 357 00:17:16,000 --> 00:17:18,040 of-- if you happen to look up all of them 358 00:17:18,040 --> 00:17:21,490 online, for some reason there's actually a real status code 359 00:17:21,490 --> 00:17:26,619 called 418 I'm a teapot. 360 00:17:26,619 --> 00:17:29,610 >> I googled where the origin of this was from. 361 00:17:29,610 --> 00:17:33,150 And apparently one April Fools' Day a couple decades ago, 362 00:17:33,150 --> 00:17:36,415 someone thought it would be hilarious to create a new status code called 418 363 00:17:36,415 --> 00:17:37,380 I'm a teapot. 364 00:17:37,380 --> 00:17:40,760 Legitimately, the name of this code is called I'm a teapot. 365 00:17:40,760 --> 00:17:43,670 >> I forget what page you have to go to actually make this display. 366 00:17:43,670 --> 00:17:47,955 But apparently, you can actually obtain a status code of I'm 367 00:17:47,955 --> 00:17:51,400 a teapot somehow through doing something. 368 00:17:51,400 --> 00:17:54,480 So there's hundreds and hundreds of status codes. 369 00:17:54,480 --> 00:17:56,730 >> Some of them make more sense than others. 370 00:17:56,730 --> 00:18:01,430 But pretty much just familiarize yourself with the most common ones. 371 00:18:01,430 --> 00:18:04,090 The requested entity body is short and stout, apparently. 372 00:18:04,090 --> 00:18:07,990 >> So sometimes there are more frightening errors than I'm a teapot. 373 00:18:07,990 --> 00:18:11,210 But this is one that I guess you kind of hope to hit. 374 00:18:11,210 --> 00:18:14,130 But I don't think you will. 375 00:18:14,130 --> 00:18:17,260 Everyone good on just status codes, requests, processes, making 376 00:18:17,260 --> 00:18:19,155 sure information is delivered properly? 377 00:18:19,155 --> 00:18:22,270 378 00:18:22,270 --> 00:18:26,120 >> So now we're going to transition into of a fun part of section today, 379 00:18:26,120 --> 00:18:28,500 where we talk a little bit about HTML. 380 00:18:28,500 --> 00:18:32,580 HTML, all it is HyperText Markup Language. 381 00:18:32,580 --> 00:18:35,160 It's just the standard language you use to create all web 382 00:18:35,160 --> 00:18:36,690 pages on the internet. 383 00:18:36,690 --> 00:18:39,560 >> So any web page, what's your favorite web page? 384 00:18:39,560 --> 00:18:40,855 What's your favorite web page? 385 00:18:40,855 --> 00:18:41,771 >> AUDIENCE: [INAUDIBLE]. 386 00:18:41,771 --> 00:18:42,270 387 00:18:42,270 --> 00:18:43,090 ANDI PENG: Sorry? 388 00:18:43,090 --> 00:18:43,980 >> AUDIENCE: Tumblr. 389 00:18:43,980 --> 00:18:44,730 >> ANDI PENG: Tumblr. 390 00:18:44,730 --> 00:18:46,800 So Tumblr is written in HTML. 391 00:18:46,800 --> 00:18:50,700 And so we'll actually go through and play around with some of these things 392 00:18:50,700 --> 00:18:51,980 later on. 393 00:18:51,980 --> 00:18:54,980 Pretty much everything you need to learn, to know, 394 00:18:54,980 --> 00:18:58,540 to write HTML you can probably just Google on the internet. 395 00:18:58,540 --> 00:19:04,490 >> HTML, it's not a program like C where you can create variables and do 396 00:19:04,490 --> 00:19:05,600 cool things with it. 397 00:19:05,600 --> 00:19:08,747 It's more of just, oh, this is how I want things to appear on my website. 398 00:19:08,747 --> 00:19:10,080 And I'm just going to put it in. 399 00:19:10,080 --> 00:19:12,160 And it's going to style it. 400 00:19:12,160 --> 00:19:15,650 >> So HTML, in a sense, it's just like a formatting or template language. 401 00:19:15,650 --> 00:19:16,680 It's a lot easier. 402 00:19:16,680 --> 00:19:19,030 It's a lot easier to learn, a lot easier to write in 403 00:19:19,030 --> 00:19:21,450 than your typical programming language, very easy, 404 00:19:21,450 --> 00:19:24,310 very user accessible and friendly. 405 00:19:24,310 --> 00:19:29,040 >> So we're actually going to play around, write our own pages today. 406 00:19:29,040 --> 00:19:32,900 But before we begin, I just want to go over some brief best practices. 407 00:19:32,900 --> 00:19:35,660 Because HTML is such an easy language and because even 408 00:19:35,660 --> 00:19:39,012 if you do a couple things wrong, it sometimes may not notice, 409 00:19:39,012 --> 00:19:41,970 we want to make sure that we're actually adhering to our best practices 410 00:19:41,970 --> 00:19:44,490 to make sure that things that could be going around but 411 00:19:44,490 --> 00:19:49,660 aren't always going to not go right make sure that they're minimized. 412 00:19:49,660 --> 00:19:53,570 >> So pretty much, make sure your closing all your tags 413 00:19:53,570 --> 00:19:54,737 when you're writing in HTML. 414 00:19:54,737 --> 00:19:56,486 If you're opening a body, make sure you're 415 00:19:56,486 --> 00:19:58,015 closing it with a body somewhere. 416 00:19:58,015 --> 00:20:00,720 You want to make sure that your web page validates by using 417 00:20:00,720 --> 00:20:02,070 what's called the W3 Validator. 418 00:20:02,070 --> 00:20:05,460 You can just Google that online, and there's a link to it. 419 00:20:05,460 --> 00:20:07,820 >> And then you want to separate HTML, which 420 00:20:07,820 --> 00:20:13,060 is your markup language from your style, which is the CSS language that David 421 00:20:13,060 --> 00:20:17,510 demonstrated that we're also going to play a bit with lecture. 422 00:20:17,510 --> 00:20:19,120 Cool. 423 00:20:19,120 --> 00:20:23,500 So anytime you want to run HTML on the CS50 appliance, 424 00:20:23,500 --> 00:20:26,240 we're going to run a program called apache, 425 00:20:26,240 --> 00:20:29,810 which all it is just a built in web server that everyone in CS50 426 00:20:29,810 --> 00:20:31,410 has access to. 427 00:20:31,410 --> 00:20:35,700 We call it apache50 just because we like to call everything 50 in CS50. 428 00:20:35,700 --> 00:20:39,610 >> So the way that you start the CS50 web server is by typing on your command 429 00:20:39,610 --> 00:20:42,860 line apache50 start dot. 430 00:20:42,860 --> 00:20:46,665 And if you want to end it at any time, you do apache50 end no dot. 431 00:20:46,665 --> 00:20:47,910 And you just hit Enter. 432 00:20:47,910 --> 00:20:50,810 And it should be heading up here soon. 433 00:20:50,810 --> 00:20:53,630 434 00:20:53,630 --> 00:20:54,130 Yup. 435 00:20:54,130 --> 00:20:58,110 So I'm just going to quickly go over an example of a really brief web page. 436 00:20:58,110 --> 00:21:00,280 And we're going to spend like 10, 15 minutes playing 437 00:21:00,280 --> 00:21:04,008 around writing our own web pages. 438 00:21:04,008 --> 00:21:05,320 OK. 439 00:21:05,320 --> 00:21:07,841 So here in the IDE-- can everyone see that? 440 00:21:07,841 --> 00:21:08,340 Not, really. 441 00:21:08,340 --> 00:21:11,400 Here, I'll zoom in. 442 00:21:11,400 --> 00:21:15,850 >> I've just got this brief template here with nothing actually in it. 443 00:21:15,850 --> 00:21:20,660 We're just going to quickly write an HTML program in which we just 444 00:21:20,660 --> 00:21:22,050 say hello to the world. 445 00:21:22,050 --> 00:21:24,970 So same thing as in C, now we're just going to do it in HTML. 446 00:21:24,970 --> 00:21:28,250 Does anyone want to actually just try giving me the first thing you 447 00:21:28,250 --> 00:21:31,870 would have to put in an HTML document? 448 00:21:31,870 --> 00:21:32,850 Yeah. 449 00:21:32,850 --> 00:21:35,965 >> AUDIENCE: The brackets, the [INAUDIBLE]. 450 00:21:35,965 --> 00:21:36,590 ANDI PENG: Yep. 451 00:21:36,590 --> 00:21:47,200 452 00:21:47,200 --> 00:21:50,930 So something that's very unique to HTML that we typically traditionally 453 00:21:50,930 --> 00:21:56,080 don't encounter in other command line level programming languages 454 00:21:56,080 --> 00:21:59,890 is that we actually to specify the type of file 455 00:21:59,890 --> 00:22:01,987 that this is going to be at the top of our code. 456 00:22:01,987 --> 00:22:04,570 So in this instance-- I think that's the right command, right? 457 00:22:04,570 --> 00:22:10,050 458 00:22:10,050 --> 00:22:10,550 Yup. 459 00:22:10,550 --> 00:22:14,860 At the top, you just want to include bang DOCTYPE html in brackets just 460 00:22:14,860 --> 00:22:17,670 to tell your computer, hey, look out. 461 00:22:17,670 --> 00:22:20,050 And HTML document is coming. 462 00:22:20,050 --> 00:22:22,250 And then how do we want to start off our file? 463 00:22:22,250 --> 00:22:25,540 If we just want to say hello, have a web page that says hello to the world, 464 00:22:25,540 --> 00:22:26,915 how do we go about building this? 465 00:22:26,915 --> 00:22:32,910 466 00:22:32,910 --> 00:22:35,300 >> Actually, let's turn to Google. 467 00:22:35,300 --> 00:22:36,910 And we can actually do this. 468 00:22:36,910 --> 00:22:43,170 469 00:22:43,170 --> 00:22:43,670 Yup. 470 00:22:43,670 --> 00:22:44,840 There we go. 471 00:22:44,840 --> 00:22:47,630 So HTML. 472 00:22:47,630 --> 00:22:52,390 As you can see, my browser is actually automatically styling this for me. 473 00:22:52,390 --> 00:22:56,010 >> Same thing as in C, when you create an open curly brace, 474 00:22:56,010 --> 00:22:59,020 your browser automatically adds in a close curly brace. 475 00:22:59,020 --> 00:23:02,210 Luckily, our IDE loves to do this for us as well. 476 00:23:02,210 --> 00:23:05,490 So now we can kind of type the beginning of a tag, 477 00:23:05,490 --> 00:23:09,139 and it's going to always tell us to remember to type the end of the tag. 478 00:23:09,139 --> 00:23:10,680 I think this needs to be capitalized. 479 00:23:10,680 --> 00:23:15,510 480 00:23:15,510 --> 00:23:21,760 And then we want to add, always, a head in which is the title. 481 00:23:21,760 --> 00:23:25,270 482 00:23:25,270 --> 00:23:29,160 We just want to maybe call this hello, and then body. 483 00:23:29,160 --> 00:23:34,010 484 00:23:34,010 --> 00:23:36,310 >> And there you go. 485 00:23:36,310 --> 00:23:39,650 That is actually our HTML document. 486 00:23:39,650 --> 00:23:45,030 So the way that any HTML document is always styled in-- same thing 487 00:23:45,030 --> 00:23:46,720 with int main void. 488 00:23:46,720 --> 00:23:49,600 You always want to have HTML an open and close tag 489 00:23:49,600 --> 00:23:52,100 at the top and bottom of your code. 490 00:23:52,100 --> 00:23:56,900 >> You want to have a head inside of which contains the title, just whatever 491 00:23:56,900 --> 00:24:01,430 is going to display the tab of your web page, and then a body inside of which 492 00:24:01,430 --> 00:24:04,120 will actually display the content of whatever you want to do. 493 00:24:04,120 --> 00:24:08,220 So if you wanted to actually run this, I'm going to zoom back out. 494 00:24:08,220 --> 00:24:12,740 You can actually start apache50 start dot. 495 00:24:12,740 --> 00:24:15,650 496 00:24:15,650 --> 00:24:16,150 Cool. 497 00:24:16,150 --> 00:24:18,980 And so as you can see, now this link has popped up. 498 00:24:18,980 --> 00:24:21,940 It says your site is now available at some link below. 499 00:24:21,940 --> 00:24:25,910 So all our IDE has done-- not IDE, sorry-- yeah, 500 00:24:25,910 --> 00:24:33,280 our IDE has done is create a web link upon which all of our web pages 501 00:24:33,280 --> 00:24:35,407 can be accessed on the server. 502 00:24:35,407 --> 00:24:36,490 So let's take a look here. 503 00:24:36,490 --> 00:24:40,240 >> Let's click on this, go to hello.html. 504 00:24:40,240 --> 00:24:42,895 And you see a very simple web page for hello world. 505 00:24:42,895 --> 00:24:46,477 506 00:24:46,477 --> 00:24:47,420 OK. 507 00:24:47,420 --> 00:24:50,513 We're actually going to just have everyone-- yeah, what's up? 508 00:24:50,513 --> 00:24:52,353 >> AUDIENCE: I have a basic question. 509 00:24:52,353 --> 00:24:52,978 ANDI PENG: Yup. 510 00:24:52,978 --> 00:24:58,064 AUDIENCE: How do you save your file as an HTML? 511 00:24:58,064 --> 00:24:58,730 ANDI PENG: Yeah. 512 00:24:58,730 --> 00:25:02,960 513 00:25:02,960 --> 00:25:10,820 So if I were to create a new file, if I do New File, Untittle, if I do, 514 00:25:10,820 --> 00:25:14,390 section.html, boom, that's all I have to do. 515 00:25:14,390 --> 00:25:15,363 >> AUDIENCE: [INAUDIBLE]? 516 00:25:15,363 --> 00:25:15,946 ANDI PENG: No. 517 00:25:15,946 --> 00:25:16,660 AUDIENCE: [INAUDIBLE]. 518 00:25:16,660 --> 00:25:17,240 ANDI PENG: No. 519 00:25:17,240 --> 00:25:18,156 AUDIENCE: [INAUDIBLE]. 520 00:25:18,156 --> 00:25:19,110 ANDI PENG: Yeah. 521 00:25:19,110 --> 00:25:24,300 Pretty much, the extension on the file that is inside your IDE, 522 00:25:24,300 --> 00:25:27,840 that tells the computer, that tells the browser, hey, look out. 523 00:25:27,840 --> 00:25:30,480 This is going to be code written in this language. 524 00:25:30,480 --> 00:25:34,240 So for example, in Microsoft Word, what do all Word documents 525 00:25:34,240 --> 00:25:37,070 end with, what extension? 526 00:25:37,070 --> 00:25:39,830 .doc or .docx, right? 527 00:25:39,830 --> 00:25:42,299 >> All that does is specifies to your operating system, hey, 528 00:25:42,299 --> 00:25:43,840 you've got a Word document coming up. 529 00:25:43,840 --> 00:25:44,940 Open it with Word. 530 00:25:44,940 --> 00:25:46,955 Same thing with PDFs. 531 00:25:46,955 --> 00:25:49,650 It knows, oh, I need to open up this file 532 00:25:49,650 --> 00:25:52,020 with Adobe Reader or Adobe Acrobat. 533 00:25:52,020 --> 00:25:56,130 >> And so extensions operate the same way as in your computer. 534 00:25:56,130 --> 00:26:00,750 If you specify your code page to be named HTML, then it knows, 535 00:26:00,750 --> 00:26:01,880 oh, you've got HTML code. 536 00:26:01,880 --> 00:26:04,890 I'm going to treat it as html code. 537 00:26:04,890 --> 00:26:06,600 So it's super smart in that sense. 538 00:26:06,600 --> 00:26:11,360 539 00:26:11,360 --> 00:26:18,730 >> So everyone, let's take like 10 minutes and just create our own websites. 540 00:26:18,730 --> 00:26:21,020 Let's add in the lovely things. 541 00:26:21,020 --> 00:26:23,440 Feel free to say whatever you want. 542 00:26:23,440 --> 00:26:27,890 I just want to make sure that everyone's servers are running correctly 543 00:26:27,890 --> 00:26:31,220 before we free you into the pset. 544 00:26:31,220 --> 00:26:33,490 Because if your servers don't run for the pset, 545 00:26:33,490 --> 00:26:34,847 that will be really, really bad. 546 00:26:34,847 --> 00:27:17,380 547 00:27:17,380 --> 00:27:21,093 >> I'm just going to float around and see what everyone's working on. 548 00:27:21,093 --> 00:27:26,965 549 00:27:26,965 --> 00:27:27,590 How's it going? 550 00:27:27,590 --> 00:27:29,048 >> AUDIENCE: I just turned on my computer. 551 00:27:29,048 --> 00:27:29,923 >> ANDI PENG: That's OK. 552 00:27:29,923 --> 00:27:41,200 553 00:27:41,200 --> 00:27:42,390 >> AUDIENCE: [INAUDIBLE]. 554 00:27:42,390 --> 00:27:44,284 >> ANDI PENG: Just your IDE. 555 00:27:44,284 --> 00:27:44,784 Yeah. 556 00:27:44,784 --> 00:27:54,040 557 00:27:54,040 --> 00:27:55,910 >> AUDIENCE: [INAUDIBLE]. 558 00:27:55,910 --> 00:27:57,590 >> ANDI PENG: It's OK. 559 00:27:57,590 --> 00:27:59,491 >> AUDIENCE: [INAUDIBLE]. 560 00:27:59,491 --> 00:28:00,490 ANDI PENG: Totally fine. 561 00:28:00,490 --> 00:28:47,705 562 00:28:47,705 --> 00:28:51,530 Is everyone accessing their web server OK? 563 00:28:51,530 --> 00:28:52,970 Is apache50 running OK? 564 00:28:52,970 --> 00:28:54,700 I think in some of the other sections, we 565 00:28:54,700 --> 00:28:58,790 had issues with people not being able to access the server. 566 00:28:58,790 --> 00:28:59,290 Yeah. 567 00:28:59,290 --> 00:29:05,764 So you just run apache50 space start space period. 568 00:29:05,764 --> 00:29:06,680 AUDIENCE: [INAUDIBLE]. 569 00:29:06,680 --> 00:29:07,610 ANDI PENG: Yup. 570 00:29:07,610 --> 00:29:08,294 Good? 571 00:29:08,294 --> 00:29:09,210 >> AUDIENCE: [INAUDIBLE]. 572 00:29:09,210 --> 00:29:12,530 573 00:29:12,530 --> 00:29:13,350 >> ANDI PENG: Oh, OK. 574 00:29:13,350 --> 00:29:14,808 So you're supposed to have a space. 575 00:29:14,808 --> 00:29:15,425 So apache50-- 576 00:29:15,425 --> 00:29:16,115 >> AUDIENCE: I did. 577 00:29:16,115 --> 00:29:17,661 >> ANDI PENG: --start space. 578 00:29:17,661 --> 00:29:18,660 AUDIENCE: Oh, space dot. 579 00:29:18,660 --> 00:29:20,110 ANDI PENG: Yup, space dot. 580 00:29:20,110 --> 00:29:23,230 There you go. 581 00:29:23,230 --> 00:29:25,490 So then if you have an HTML page created, 582 00:29:25,490 --> 00:29:28,560 then you can just go directly to the link that it specifies. 583 00:29:28,560 --> 00:29:30,539 And you should be able to access it. 584 00:29:30,539 --> 00:29:35,130 585 00:29:35,130 --> 00:29:37,876 >> Everyone been able to access their web pages OK? 586 00:29:37,876 --> 00:29:39,339 >> AUDIENCE: [INAUDIBLE]. 587 00:29:39,339 --> 00:29:40,380 ANDI PENG: Oh, that's OK. 588 00:29:40,380 --> 00:29:43,551 589 00:29:43,551 --> 00:29:44,964 >> AUDIENCE: [INAUDIBLE]. 590 00:29:44,964 --> 00:29:45,630 ANDI PENG: Yeah. 591 00:29:45,630 --> 00:29:48,171 I think you can actually open it within your browser, browser 592 00:29:48,171 --> 00:29:49,955 and not just your IDE browser. 593 00:29:49,955 --> 00:29:51,580 Yeah, I think if you copy and paste it. 594 00:29:51,580 --> 00:29:53,920 >> AUDIENCE: And then how do we turn it off? 595 00:29:53,920 --> 00:29:54,590 [INAUDIBLE] 596 00:29:54,590 --> 00:29:58,720 >> ANDI PENG: Yeah, you do apache50 stop with no period. 597 00:29:58,720 --> 00:29:59,220 Yup. 598 00:29:59,220 --> 00:30:01,180 >> AUDIENCE: [INAUDIBLE]. 599 00:30:01,180 --> 00:30:02,768 >> ANDI PENG: With no period. 600 00:30:02,768 --> 00:30:04,051 Yeah. 601 00:30:04,051 --> 00:30:04,550 There we go. 602 00:30:04,550 --> 00:30:05,050 Yup. 603 00:30:05,050 --> 00:30:08,480 604 00:30:08,480 --> 00:30:09,855 We're creating our own web pages. 605 00:30:09,855 --> 00:30:10,646 >> AUDIENCE: Oh, cool. 606 00:30:10,646 --> 00:30:13,396 607 00:30:13,396 --> 00:30:14,062 ANDI PENG: Yeah. 608 00:30:14,062 --> 00:30:20,484 609 00:30:20,484 --> 00:30:22,420 >> AUDIENCE: I have a question. 610 00:30:22,420 --> 00:30:25,294 So apache 50-- 611 00:30:25,294 --> 00:30:26,731 >> ANDI PENG: 50, yeah. 612 00:30:26,731 --> 00:30:28,168 >> AUDIENCE: [INAUDIBLE]. 613 00:30:28,168 --> 00:30:29,130 >> ANDI PENG: What? 614 00:30:29,130 --> 00:30:29,750 That is weird. 615 00:30:29,750 --> 00:30:32,244 See, that was kind of the issue that was happening before. 616 00:30:32,244 --> 00:30:37,820 617 00:30:37,820 --> 00:30:38,730 OK. 618 00:30:38,730 --> 00:30:39,800 See me after section. 619 00:30:39,800 --> 00:30:42,320 Because we are having some issues with the server. 620 00:30:42,320 --> 00:30:44,325 >> And you want to make sure that your server is 621 00:30:44,325 --> 00:30:45,700 running before starting the pset. 622 00:30:45,700 --> 00:30:47,800 Because you're going to need it. 623 00:30:47,800 --> 00:30:48,300 Yeah. 624 00:30:48,300 --> 00:30:51,299 Is there anyone else that hasn't been able to get their server to start? 625 00:30:51,299 --> 00:31:12,410 626 00:31:12,410 --> 00:31:17,840 >> For those of you who want to add additional style to your web pages, 627 00:31:17,840 --> 00:31:20,450 we can actually do what David did in lecture as well, 628 00:31:20,450 --> 00:31:24,070 which is create an additional style sheet, which is a dot CSS, Cascading 629 00:31:24,070 --> 00:31:30,080 Style Sheet and actually just add it in. 630 00:31:30,080 --> 00:31:33,550 So for example, I've just created pretty much almost the exact same one 631 00:31:33,550 --> 00:31:37,180 David did in lecture. 632 00:31:37,180 --> 00:31:39,220 You can pretty much just do body. 633 00:31:39,220 --> 00:31:45,980 >> You have what are called tags in which you can apply to IDE whatever section 634 00:31:45,980 --> 00:31:48,650 you want within your actual to HTML page. 635 00:31:48,650 --> 00:31:54,890 So the body of the page, you can do text align center. 636 00:31:54,890 --> 00:31:58,110 And then I'll creative a tag called top inside 637 00:31:58,110 --> 00:32:01,860 of which I want these things to happen, assign a larger pixel size 638 00:32:01,860 --> 00:32:03,104 for the font. 639 00:32:03,104 --> 00:32:04,520 I want the font weight to be bold. 640 00:32:04,520 --> 00:32:06,478 And I want the color to be blue, just arbitrary 641 00:32:06,478 --> 00:32:08,570 values that I decided to choose. 642 00:32:08,570 --> 00:32:10,870 I can create another tag called middle. 643 00:32:10,870 --> 00:32:12,640 Font size, make it a bit smaller. 644 00:32:12,640 --> 00:32:17,730 And then I can create another tag called bottom where I want the font size 645 00:32:17,730 --> 00:32:20,900 to be even smaller still. 646 00:32:20,900 --> 00:32:25,630 >> And so pretty much this is just example of source code or source style sheets 647 00:32:25,630 --> 00:32:27,400 that it's very easy to just Google. 648 00:32:27,400 --> 00:32:31,560 If you say, oh, I want my font to be italicized and dark green, 649 00:32:31,560 --> 00:32:33,980 you can probably Google, and then it will tell you 650 00:32:33,980 --> 00:32:37,590 the appropriate tags or IDs to create. 651 00:32:37,590 --> 00:32:41,670 And so the way that you would actually kind of have this in an HTML document 652 00:32:41,670 --> 00:32:45,660 or use it is all you have to do here is at the head 653 00:32:45,660 --> 00:32:48,560 add a link to the style sheet. 654 00:32:48,560 --> 00:32:53,600 >> So you can just link href equals whatever the name of your style sheet 655 00:32:53,600 --> 00:32:54,590 is. 656 00:32:54,590 --> 00:32:56,740 And then the relationship is a style sheet. 657 00:32:56,740 --> 00:33:00,700 So within any HTML document, as long as you include this dot CSS sheet, 658 00:33:00,700 --> 00:33:07,140 you should be able to access and have the properties there. 659 00:33:07,140 --> 00:33:10,370 >> So for example, here I've just create another example web page. 660 00:33:10,370 --> 00:33:15,680 This is welcome to CS50 section Tuesdays from 2:00 to 3:30 with me. 661 00:33:15,680 --> 00:33:20,300 And then I've added a lovely image that we potentially should be able to see. 662 00:33:20,300 --> 00:33:24,620 >> So if you take a look here, if you go to style.html, 663 00:33:24,620 --> 00:33:26,310 we created a web page with kittens. 664 00:33:26,310 --> 00:33:29,420 Because kitten are awesome. 665 00:33:29,420 --> 00:33:33,570 So adding an image is just img SRC link. 666 00:33:33,570 --> 00:33:36,260 667 00:33:36,260 --> 00:33:38,310 >> Pretty much, if there's any sort of feature 668 00:33:38,310 --> 00:33:40,268 you want to add to your website-- so let's say, 669 00:33:40,268 --> 00:33:43,290 you want to add a menu or a search bar or like 670 00:33:43,290 --> 00:33:46,450 an image-- just Google how to do that. 671 00:33:46,450 --> 00:33:48,277 And you just plop in that format. 672 00:33:48,277 --> 00:33:50,110 And you can just pretty much just add it in. 673 00:33:50,110 --> 00:33:52,670 It's really, really easy. 674 00:33:52,670 --> 00:33:55,014 >> We are creating our own web pages right now. 675 00:33:55,014 --> 00:33:55,680 If you want to-- 676 00:33:55,680 --> 00:33:56,580 >> AUDIENCE: [INAUDIBLE] 677 00:33:56,580 --> 00:33:57,470 >> ANDI PENG: Sorry? 678 00:33:57,470 --> 00:33:59,310 >> AUDIENCE: [INAUDIBLE]. 679 00:33:59,310 --> 00:34:01,340 >> ANDI PENG: Oh, the div is just a division 680 00:34:01,340 --> 00:34:04,370 telling me that, oh, I have a certain section called 681 00:34:04,370 --> 00:34:07,480 middle in which I'm applying my CSS tag, and then 682 00:34:07,480 --> 00:34:09,619 my other division with the bottom. 683 00:34:09,619 --> 00:34:10,785 That's all it's telling you. 684 00:34:10,785 --> 00:34:12,743 Because it's nice to keep things neat in order, 685 00:34:12,743 --> 00:34:16,304 so the program knows how exactly to run. 686 00:34:16,304 --> 00:34:18,929 And think I can copy paste this into my actual browser as well. 687 00:34:18,929 --> 00:34:21,110 It should be fine. 688 00:34:21,110 --> 00:34:21,610 Yeah. 689 00:34:21,610 --> 00:34:24,330 690 00:34:24,330 --> 00:34:25,989 Yay. 691 00:34:25,989 --> 00:34:29,380 So if everyone wants to just try creating a web page, 692 00:34:29,380 --> 00:34:32,169 we'll take another two to three minutes. 693 00:34:32,169 --> 00:34:34,460 I just want to make sure everyone's servers are running 694 00:34:34,460 --> 00:34:36,941 and everyone has an idea of how to do that. 695 00:34:36,941 --> 00:34:38,774 If you guys want to take out your computers. 696 00:34:38,774 --> 00:34:44,630 697 00:34:44,630 --> 00:34:45,635 Still not working? 698 00:34:45,635 --> 00:34:47,420 >> AUDIENCE: I'm just [INAUDIBLE]. 699 00:34:47,420 --> 00:34:49,838 >> ANDI PENG: Maybe try update 50 as well. 700 00:34:49,838 --> 00:34:51,392 Yeah. 701 00:34:51,392 --> 00:34:52,308 AUDIENCE: [INAUDIBLE]. 702 00:34:52,308 --> 00:35:17,502 703 00:35:17,502 --> 00:35:18,990 >> ANDI PENG: Yeah. 704 00:35:18,990 --> 00:35:23,750 So the way that you start a new web server on the IDE is just 705 00:35:23,750 --> 00:35:27,889 do apache50 space start space dot. 706 00:35:27,889 --> 00:35:30,430 I just wanted to make sure everyone's servers are running OK. 707 00:35:30,430 --> 00:35:31,763 >> AUDIENCE: Here, on the terminal? 708 00:35:31,763 --> 00:35:33,334 ANDI PENG: Yeah. 709 00:35:33,334 --> 00:35:34,250 AUDIENCE: [INAUDIBLE]. 710 00:35:34,250 --> 00:35:38,000 711 00:35:38,000 --> 00:35:38,985 >> ANDI PENG: Apache. 712 00:35:38,985 --> 00:35:42,010 Actually, I think you're running something already. 713 00:35:42,010 --> 00:35:43,145 Yeah, you're actually running a different server. 714 00:35:43,145 --> 00:35:43,830 Yeah, you're good. 715 00:35:43,830 --> 00:35:45,085 As long as that's working, you're OK. 716 00:35:45,085 --> 00:35:45,626 >> AUDIENCE: OK. 717 00:35:45,626 --> 00:35:47,615 ANDI PENG: There's two ways to run servers. 718 00:35:47,615 --> 00:35:49,990 So as long as one of the ways is working, it's all right. 719 00:35:49,990 --> 00:36:18,470 720 00:36:18,470 --> 00:36:21,680 We'll take another minute just to kind of finish up 721 00:36:21,680 --> 00:36:25,280 the finishing touches of whatever web page you guys wanted to make. 722 00:36:25,280 --> 00:36:26,830 >> Is everyone working by the way? 723 00:36:26,830 --> 00:36:30,910 Everyone's servers are running besides for yours? 724 00:36:30,910 --> 00:36:32,210 We'll figure that out. 725 00:36:32,210 --> 00:36:34,137 And HTML's fairly simple. 726 00:36:34,137 --> 00:36:35,220 So I think we're all good. 727 00:36:35,220 --> 00:36:38,260 728 00:36:38,260 --> 00:36:38,760 Yeah. 729 00:36:38,760 --> 00:36:41,070 I'll come back. 730 00:36:41,070 --> 00:36:42,797 >> AUDIENCE: [INAUDIBLE]. 731 00:36:42,797 --> 00:36:43,380 ANDI PENG: OK. 732 00:36:43,380 --> 00:36:44,770 AUDIENCE: So it's just started to load up. 733 00:36:44,770 --> 00:36:45,686 ANDI PENG: No worries. 734 00:36:45,686 --> 00:36:49,590 735 00:36:49,590 --> 00:36:52,680 So HTML, there's source code that will be online after section. 736 00:36:52,680 --> 00:36:54,810 Also, David has a whole bunch online as well. 737 00:36:54,810 --> 00:36:58,190 Just kind of glance over it to see how HTML pages are written. 738 00:36:58,190 --> 00:36:59,920 It's fairly easy. 739 00:36:59,920 --> 00:37:03,979 Anything you don't know, you pretty much just Google and you're good. 740 00:37:03,979 --> 00:37:06,270 I just want to make sure that your servers are running. 741 00:37:06,270 --> 00:37:12,962 742 00:37:12,962 --> 00:37:14,880 >> AUDIENCE: Does it do this often? 743 00:37:14,880 --> 00:37:16,421 >> ANDI PENG: It's never happened to me. 744 00:37:16,421 --> 00:37:18,470 745 00:37:18,470 --> 00:37:20,782 I didn't know it could even hibernate. 746 00:37:20,782 --> 00:37:22,516 >> AUDIENCE: [INAUDIBLE]. 747 00:37:22,516 --> 00:37:25,140 ANDI PENG: I think everyone-- mine has never hibernated before. 748 00:37:25,140 --> 00:37:26,860 And I don't know why. 749 00:37:26,860 --> 00:37:27,566 It's weird. 750 00:37:27,566 --> 00:37:29,310 >> AUDIENCE: [INAUDIBLE]. 751 00:37:29,310 --> 00:37:30,643 >> ANDI PENG: Is yours hibernating? 752 00:37:30,643 --> 00:37:32,615 753 00:37:32,615 --> 00:37:33,669 >> AUDIENCE: [INAUDIBLE]. 754 00:37:33,669 --> 00:37:34,335 ANDI PENG: Yeah. 755 00:37:34,335 --> 00:37:39,122 756 00:37:39,122 --> 00:37:39,872 AUDIENCE: It's OK. 757 00:37:39,872 --> 00:37:40,622 So once it's open. 758 00:37:40,622 --> 00:37:41,760 ANDI PENG: OK. 759 00:37:41,760 --> 00:37:43,940 We'll deal with some server issues after section. 760 00:37:43,940 --> 00:37:44,860 You should be fine. 761 00:37:44,860 --> 00:37:47,950 Although, you want to make sure you get them resolved before you leave. 762 00:37:47,950 --> 00:37:49,380 Because if your server's not running, then you're 763 00:37:49,380 --> 00:37:52,004 not going to be able to do the pset, like any part of the pset. 764 00:37:52,004 --> 00:37:54,200 So you want to make sure that that's working. 765 00:37:54,200 --> 00:37:54,831 Cool. 766 00:37:54,831 --> 00:37:55,330 All right. 767 00:37:55,330 --> 00:37:56,490 Say goodbye kittens. 768 00:37:56,490 --> 00:37:59,670 I spent a long time looking for that kitten picture to put on. 769 00:37:59,670 --> 00:38:02,272 So, anyways. 770 00:38:02,272 --> 00:38:04,950 >> AUDIENCE: [INAUDIBLE]. 771 00:38:04,950 --> 00:38:05,770 >> ANDI PENG: Sorry? 772 00:38:05,770 --> 00:38:07,345 >> AUDIENCE: [INAUDIBLE]. 773 00:38:07,345 --> 00:38:08,970 ANDI PENG: I think it's on the website. 774 00:38:08,970 --> 00:38:11,064 Like the spec? 775 00:38:11,064 --> 00:38:12,020 >> AUDIENCE: [INAUDIBLE]. 776 00:38:12,020 --> 00:38:16,080 I think the spec is just online in week seven. 777 00:38:16,080 --> 00:38:18,850 I think it's called pset6, even though we're on week seven, which 778 00:38:18,850 --> 00:38:19,641 is a bit computing. 779 00:38:19,641 --> 00:38:23,130 AUDIENCE: But I mean if you want to look at-- if you 780 00:38:23,130 --> 00:38:28,666 want to pull up our version of the web site from our sever? 781 00:38:28,666 --> 00:38:31,820 So like server.c is the pset, right? 782 00:38:31,820 --> 00:38:36,514 If you want to look at this, like how it checks out? 783 00:38:36,514 --> 00:38:38,680 ANDI PENG: Oh, so actually the pset, all we're doing 784 00:38:38,680 --> 00:38:41,405 here is implementing-- here, I'll go over this briefly. 785 00:38:41,405 --> 00:38:44,187 786 00:38:44,187 --> 00:38:47,020 So for everyone that's just gotten to section, you guys are in luck. 787 00:38:47,020 --> 00:38:49,340 There is very little material to actually cover today. 788 00:38:49,340 --> 00:38:52,585 >> I'm just going to spend the next 20 minutes going over pset help. 789 00:38:52,585 --> 00:38:55,210 Because there's some useful functions that will help your life. 790 00:38:55,210 --> 00:38:57,501 And hopefully, we'll be out of here in like 20 minutes. 791 00:38:57,501 --> 00:38:58,360 OK. 792 00:38:58,360 --> 00:39:00,252 >> So pset7 is wrong. 793 00:39:00,252 --> 00:39:02,460 Even though we're on week seven, it's actually pset6. 794 00:39:02,460 --> 00:39:04,220 I'll change that. 795 00:39:04,220 --> 00:39:07,550 All we're doing in pset6 is creating a web server. 796 00:39:07,550 --> 00:39:09,010 That sounds super scary. 797 00:39:09,010 --> 00:39:11,010 >> And especially for those of you who have already 798 00:39:11,010 --> 00:39:14,530 looked at the distribution code, there's a lot of code, a lot of code. 799 00:39:14,530 --> 00:39:15,570 But is totally OK. 800 00:39:15,570 --> 00:39:17,750 Because the nitty gritty part of actually creating 801 00:39:17,750 --> 00:39:20,140 the server is done by us. 802 00:39:20,140 --> 00:39:22,090 All you're really asked to do in this pset 803 00:39:22,090 --> 00:39:25,350 is just to do some string manipulation in file I/O. It's actually 804 00:39:25,350 --> 00:39:27,570 like fairly simple. 805 00:39:27,570 --> 00:39:30,830 >> So when you first download that-- who here has actually already downloaded 806 00:39:30,830 --> 00:39:32,540 the pset and taken a look? 807 00:39:32,540 --> 00:39:33,040 All right. 808 00:39:33,040 --> 00:39:33,540 Yeah. 809 00:39:33,540 --> 00:39:36,042 There's like 500 lines of code that you're going to be like, 810 00:39:36,042 --> 00:39:36,750 what is going on? 811 00:39:36,750 --> 00:39:38,177 And that's totally fine. 812 00:39:38,177 --> 00:39:39,760 Make sure you watch the walk-throughs. 813 00:39:39,760 --> 00:39:41,610 Because David and-- I don't know. 814 00:39:41,610 --> 00:39:43,870 I don't think it's Zamyla's, this one. 815 00:39:43,870 --> 00:39:47,040 But I think some other walk-throughs are fairly 816 00:39:47,040 --> 00:39:49,510 helpful in terms of just letting you know 817 00:39:49,510 --> 00:39:51,780 what is going on inside of your code. 818 00:39:51,780 --> 00:39:53,330 >> And it's totally OK. 819 00:39:53,330 --> 00:39:57,860 Because the four functions that you're asked to implement have actually 820 00:39:57,860 --> 00:39:59,720 zero to do with the actual server. 821 00:39:59,720 --> 00:40:02,590 All they have to do is just parsing different strings, 822 00:40:02,590 --> 00:40:05,780 searching through strings, to make sure things are doing 823 00:40:05,780 --> 00:40:07,750 what they're supposed to be doing. 824 00:40:07,750 --> 00:40:11,200 >> So to that effect, there are some very, very useful functions, 825 00:40:11,200 --> 00:40:13,630 especially for string manipulation, that we should all 826 00:40:13,630 --> 00:40:15,879 go over that I thought I'd be very useful for you guys 827 00:40:15,879 --> 00:40:19,130 to learn before attempting the pset. 828 00:40:19,130 --> 00:40:23,350 And they're all contained within your string.h library. 829 00:40:23,350 --> 00:40:25,980 There's probably more useful functions I haven't included here, 830 00:40:25,980 --> 00:40:30,740 because I either never use them or perhaps I just didn't know they exist. 831 00:40:30,740 --> 00:40:32,440 >> Feel free to glance through student.h. 832 00:40:32,440 --> 00:40:36,460 Because there's going to be a lot of functions that are very useful. 833 00:40:36,460 --> 00:40:43,050 So the six that I use the most in my pset when I was doing it this past week 834 00:40:43,050 --> 00:40:49,620 were strtok, strchr, strrcher, strstr, strcasecmp, and strcpy. 835 00:40:49,620 --> 00:40:53,060 And so the last two may seem pretty familiar to most of you. 836 00:40:53,060 --> 00:40:56,910 Str case compare, all it does is compare strings to check them for equality, 837 00:40:56,910 --> 00:40:58,110 including case. 838 00:40:58,110 --> 00:41:01,430 And strcpy just copies one string into a buffer. 839 00:41:01,430 --> 00:41:04,430 >> And so those two should seem very familiar to you guys at this point. 840 00:41:04,430 --> 00:41:07,100 Because we've used them a lot, especially for the last psets. 841 00:41:07,100 --> 00:41:10,734 But the first four perhaps you haven't seen up until now. 842 00:41:10,734 --> 00:41:12,400 But I'm going to just walk through them. 843 00:41:12,400 --> 00:41:15,620 Because they're going to make your lives really, really easy for-- not easy, 844 00:41:15,620 --> 00:41:19,830 but much easier for this upcoming pset. 845 00:41:19,830 --> 00:41:20,420 >> OK. 846 00:41:20,420 --> 00:41:27,720 So char* strtok, this is the function definition for this function contained 847 00:41:27,720 --> 00:41:31,050 within the string,h library. 848 00:41:31,050 --> 00:41:34,340 If you are given an input of char* string, which is just a string, 849 00:41:34,340 --> 00:41:38,220 or a constant char* deliminator, delim for short, 850 00:41:38,220 --> 00:41:42,410 all it's doing is breaking the larger string into a series of what we call 851 00:41:42,410 --> 00:41:45,730 tokens separated by a certain value. 852 00:41:45,730 --> 00:42:03,340 So in a sense, if I were to give you section.7.php, this is a string. 853 00:42:03,340 --> 00:42:09,520 >> So that would be if I were to pass in this as my str, my char* str, 854 00:42:09,520 --> 00:42:18,870 if my deliminator was dot, all this would do is search through string. 855 00:42:18,870 --> 00:42:22,790 And the first time it sees a dot, it would just return to the pointer 856 00:42:22,790 --> 00:42:25,830 to the last token found in the string before this. 857 00:42:25,830 --> 00:42:27,230 So it would go right here. 858 00:42:27,230 --> 00:42:30,580 >> And it would just give me 7.php. 859 00:42:30,580 --> 00:42:34,070 And if I were to call the function one more time, 860 00:42:34,070 --> 00:42:37,580 it would give me just the .php. 861 00:42:37,580 --> 00:42:41,540 And so all this function is doing is breaking down the larger string 862 00:42:41,540 --> 00:42:44,620 into smaller strings depending on what you're looking for. 863 00:42:44,620 --> 00:42:46,670 >> And so for example, in your look up function 864 00:42:46,670 --> 00:42:49,895 if you want to look at what certain characters come about 865 00:42:49,895 --> 00:42:54,280 or if dots happen or extensions happen, this function would be fairly useful. 866 00:42:54,280 --> 00:42:57,260 867 00:42:57,260 --> 00:42:59,010 Yeah. 868 00:42:59,010 --> 00:42:59,510 No worries. 869 00:42:59,510 --> 00:43:01,339 This will all be-- yeah, what's up? 870 00:43:01,339 --> 00:43:07,087 >> AUDIENCE: So in the first line, if we were using this example, 871 00:43:07,087 --> 00:43:09,504 what would we insert into that? 872 00:43:09,504 --> 00:43:10,170 ANDI PENG: Yeah. 873 00:43:10,170 --> 00:43:13,000 874 00:43:13,000 --> 00:43:25,640 You would just call a strtok string comma delim. 875 00:43:25,640 --> 00:43:30,260 And string is equal to section.7.php. 876 00:43:30,260 --> 00:43:35,244 And then you're delim could be equal to just dot. 877 00:43:35,244 --> 00:43:36,654 >> AUDIENCE: OK. 878 00:43:36,654 --> 00:43:39,010 >> ANDI PENG: Yeah. 879 00:43:39,010 --> 00:43:41,266 Just like that. 880 00:43:41,266 --> 00:43:43,890 All these functions are fairly similar when we go through them. 881 00:43:43,890 --> 00:43:45,514 They just do slightly different things. 882 00:43:45,514 --> 00:43:49,530 But they're all going to make your life a lot easier. 883 00:43:49,530 --> 00:43:53,940 Second function, this one's like super, super, super important, 884 00:43:53,940 --> 00:43:58,254 is the-- hold up. 885 00:43:58,254 --> 00:44:07,560 886 00:44:07,560 --> 00:44:08,730 >> Oops. 887 00:44:08,730 --> 00:44:13,810 Strchr searches for the first occurrence-- actually, yeah. 888 00:44:13,810 --> 00:44:16,385 Strchr is the function that I definitely just went over. 889 00:44:16,385 --> 00:44:18,260 So ignore what I said for the first function. 890 00:44:18,260 --> 00:44:20,980 It's actually called strchr. 891 00:44:20,980 --> 00:44:24,840 >> So what would happened here is if you were given a string in a char c, 892 00:44:24,840 --> 00:44:28,660 it would just give you whatever that was. 893 00:44:28,660 --> 00:44:29,230 Yeah. 894 00:44:29,230 --> 00:44:33,700 So think of it as str, which is a string, and chr as char. 895 00:44:33,700 --> 00:44:38,621 So all you're trying to do is search for where a char is within a string. 896 00:44:38,621 --> 00:44:41,120 And so it searches for the first occurrence of the character 897 00:44:41,120 --> 00:44:43,601 c in the string str. 898 00:44:43,601 --> 00:44:46,463 >> AUDIENCE: [INAUDIBLE]. 899 00:44:46,463 --> 00:44:48,380 >> ANDI PENG: Yup. 900 00:44:48,380 --> 00:44:51,230 And then if it didn't find it, it's going to return NULL. 901 00:44:51,230 --> 00:44:54,313 So something that's going to be very useful for you guys in doing the pset 902 00:44:54,313 --> 00:44:59,030 if, say, you were looking for an extension like a .docx for a Word 903 00:44:59,030 --> 00:45:04,740 document or a .pdf for a PDF document, you can kind of use it to look 904 00:45:04,740 --> 00:45:08,720 for whatever is afterwards every time you see a dot, right? 905 00:45:08,720 --> 00:45:11,880 And so pretty much, if you run that through the function, 906 00:45:11,880 --> 00:45:13,610 if it returns NULL, then you know that it 907 00:45:13,610 --> 00:45:17,292 didn't find it dot, which means this clearly isn't a valid file extension. 908 00:45:17,292 --> 00:45:19,000 Or if it returns something, then you know 909 00:45:19,000 --> 00:45:21,940 it's going to return whatever's actually after the extension. 910 00:45:21,940 --> 00:45:24,190 So those of you who had started looking through lookup 911 00:45:24,190 --> 00:45:28,640 and parse, this function's going to be super useful. 912 00:45:28,640 --> 00:45:32,010 So we're actually going to demonstrate using this. 913 00:45:32,010 --> 00:45:36,670 >> Why don't you guys try writing a function bool sentence char* s that 914 00:45:36,670 --> 00:45:39,610 just returns true if s is a sentence and false otherwise. 915 00:45:39,610 --> 00:45:44,110 916 00:45:44,110 --> 00:45:46,830 So hint, you're going to probably use strchr. 917 00:45:46,830 --> 00:45:50,420 Or you just search in the string for a certain character. 918 00:45:50,420 --> 00:45:54,950 And so in a sentence, what separates a sentence 919 00:45:54,950 --> 00:45:57,510 from a non-sentence, what specific character? 920 00:45:57,510 --> 00:45:58,260 AUDIENCE: A space. 921 00:45:58,260 --> 00:45:59,343 ANDI PENG: A space, right? 922 00:45:59,343 --> 00:46:03,354 And so what do we probably going to want to do within this function here? 923 00:46:03,354 --> 00:46:04,290 >> AUDIENCE: [INAUDIBLE]. 924 00:46:04,290 --> 00:46:07,623 >> ANDI PENG: We're going to want to strchr string for the appearance of the space. 925 00:46:07,623 --> 00:46:11,330 Because if it returns something, then we know that this must be a sentence. 926 00:46:11,330 --> 00:46:14,510 That means that we must have a space in this string. 927 00:46:14,510 --> 00:46:17,660 >> If there's no space, then we know that, hey, guess it's not a string. 928 00:46:17,660 --> 00:46:20,060 It's probably just a really long word. 929 00:46:20,060 --> 00:46:23,242 So I'll give you guys a couple minutes to write this function. 930 00:46:23,242 --> 00:46:44,398 931 00:46:44,398 --> 00:46:45,874 Yeah. 932 00:46:45,874 --> 00:46:47,970 >> AUDIENCE: Did you get this string from the user? 933 00:46:47,970 --> 00:46:48,440 >> ANDI PENG: Yeah. 934 00:46:48,440 --> 00:46:49,565 So this is just a function. 935 00:46:49,565 --> 00:46:54,586 So imagine inside your main function you already have-- let's go here. 936 00:46:54,586 --> 00:47:00,040 937 00:47:00,040 --> 00:47:00,540 OK. 938 00:47:00,540 --> 00:47:05,270 So I've written this program where I have my main function where 939 00:47:05,270 --> 00:47:07,432 I've just created two strings. 940 00:47:07,432 --> 00:47:09,890 The first one is Hi, my name is Andi-- clearly, a sentence. 941 00:47:09,890 --> 00:47:13,240 My second one is just Andi, clearly not sentence. 942 00:47:13,240 --> 00:47:18,390 >> And so I'm running both of those strings through this function. 943 00:47:18,390 --> 00:47:20,540 I want you guys to write cold sentence. 944 00:47:20,540 --> 00:47:23,380 And I'm storing those values, and then just printing them out. 945 00:47:23,380 --> 00:47:26,549 So think that the user is going to pass in a string. 946 00:47:26,549 --> 00:47:29,590 And then you're going to essentially figure out if it's a sentence or not 947 00:47:29,590 --> 00:47:31,131 and return true or false accordingly. 948 00:47:31,131 --> 00:48:41,850 949 00:48:41,850 --> 00:48:45,200 >> If you guys want to give a thumbs up or heads up, head nod, 950 00:48:45,200 --> 00:48:49,080 is anyone's ready to start this, that'd be good. 951 00:48:49,080 --> 00:50:13,570 952 00:50:13,570 --> 00:50:15,200 Maybe like 30 more seconds? 953 00:50:15,200 --> 00:50:49,570 954 00:50:49,570 --> 00:50:50,070 All right. 955 00:50:50,070 --> 00:50:52,870 Let's see if you can try writing this function. 956 00:50:52,870 --> 00:50:57,480 >> So pseudo coding-- I'm just going to kind of walk through this right now. 957 00:50:57,480 --> 00:51:00,570 Pretty much, we know the function that we need to use. 958 00:51:00,570 --> 00:51:04,390 We're going to call that function on our string and search for a space. 959 00:51:04,390 --> 00:51:08,682 If it returns something, then we must know that, clearly, this is a sentence. 960 00:51:08,682 --> 00:51:09,640 Because there's spaces. 961 00:51:09,640 --> 00:51:10,930 Then we're going to return true. 962 00:51:10,930 --> 00:51:12,310 Else, we're going to return false. 963 00:51:12,310 --> 00:51:14,393 Does anyone want to give me the first line of code 964 00:51:14,393 --> 00:51:16,890 that we're actually going to use to write this? 965 00:51:16,890 --> 00:51:19,680 It's actually the hardest line of code as well. 966 00:51:19,680 --> 00:51:21,026 Yeah. 967 00:51:21,026 --> 00:51:28,942 >> AUDIENCE: If strtok s-- 968 00:51:28,942 --> 00:51:29,900 ANDI PENG: Just strchr. 969 00:51:29,900 --> 00:51:35,354 AUDIENCE: [INTERPOSING VOICES] space is not equal to null. 970 00:51:35,354 --> 00:51:38,270 971 00:51:38,270 --> 00:51:40,710 >> ANDI PENG: Cool. 972 00:51:40,710 --> 00:51:41,470 Exactly right. 973 00:51:41,470 --> 00:51:43,200 Everyone understand that first line? 974 00:51:43,200 --> 00:51:46,110 We're going to call strstr, which is a function that searches 975 00:51:46,110 --> 00:51:51,830 the string s for the char of space. 976 00:51:51,830 --> 00:51:56,010 And if it finds it, it's going to return a pointer to where that is. 977 00:51:56,010 --> 00:51:58,500 >> If it doesn't find it, it's going to return NULL. 978 00:51:58,500 --> 00:52:02,530 So if it returns anything other than NULL, then we know it's found a space. 979 00:52:02,530 --> 00:52:03,553 Does that make sense? 980 00:52:03,553 --> 00:52:04,090 Cool. 981 00:52:04,090 --> 00:52:04,590 All right. 982 00:52:04,590 --> 00:52:08,246 So if we know it's found a space, what do we want to do? 983 00:52:08,246 --> 00:52:09,162 AUDIENCE: Return true. 984 00:52:09,162 --> 00:52:09,787 ANDI PENG: Yup. 985 00:52:09,787 --> 00:52:11,940 Return true. 986 00:52:11,940 --> 00:52:15,034 And then, someone want to finish up the function for me? 987 00:52:15,034 --> 00:52:16,300 Yeah. 988 00:52:16,300 --> 00:52:19,720 Else, just like that. 989 00:52:19,720 --> 00:52:20,780 And try compiling this. 990 00:52:20,780 --> 00:52:26,071 991 00:52:26,071 --> 00:52:28,000 >> Yup. 992 00:52:28,000 --> 00:52:33,099 So as you guys can see from the outputs, remember Booleans in C 993 00:52:33,099 --> 00:52:34,390 are always expressed in binary. 994 00:52:34,390 --> 00:52:35,100 1 is true. 995 00:52:35,100 --> 00:52:36,350 0 is false. 996 00:52:36,350 --> 00:52:39,720 >> If we were to run this function on string one, which 997 00:52:39,720 --> 00:52:42,900 is Hi, my name's Andi-- clearly, a sentence-- the result 998 00:52:42,900 --> 00:52:45,700 printed out to 1 which is true. 999 00:52:45,700 --> 00:52:48,420 The second one, which is just a word, result printed out 1000 00:52:48,420 --> 00:52:50,630 to 0, which is false. 1001 00:52:50,630 --> 00:52:54,820 Everyone clear kind of on how this function was written? 1002 00:52:54,820 --> 00:52:55,800 Yeah. 1003 00:52:55,800 --> 00:52:59,770 >> AUDIENCE: Can we also do, instead of doesn't equal no, equals equals 0, 1004 00:52:59,770 --> 00:53:03,677 so that it's equal to? 1005 00:53:03,677 --> 00:53:04,260 ANDI PENG: No. 1006 00:53:04,260 --> 00:53:07,480 Because strchr is a function. 1007 00:53:07,480 --> 00:53:09,940 I'm going to back to this. 1008 00:53:09,940 --> 00:53:14,624 So what's the return type of our strchr function? 1009 00:53:14,624 --> 00:53:15,332 AUDIENCE: Oh, OK. 1010 00:53:15,332 --> 00:53:15,800 Or NULL. 1011 00:53:15,800 --> 00:53:16,466 >> ANDI PENG: Yeah. 1012 00:53:16,466 --> 00:53:20,890 It's a char* that tells me that whatever this function is going to return, 1013 00:53:20,890 --> 00:53:22,090 it's going to be a pointer. 1014 00:53:22,090 --> 00:53:24,860 Either the pointer is going to be pointing to where it's found it, 1015 00:53:24,860 --> 00:53:27,550 or it's going to return a pointer to NULL. 1016 00:53:27,550 --> 00:53:30,930 In either circumstance, it's going to return a pointer to something. 1017 00:53:30,930 --> 00:53:34,354 >> And so if you were to equate this equals, equals, 0, 1018 00:53:34,354 --> 00:53:36,020 you're going to get a compilation error. 1019 00:53:36,020 --> 00:53:37,645 Because it's going to return a pointer. 1020 00:53:37,645 --> 00:53:40,240 And you're going to try to compare a pointer to an integer. 1021 00:53:40,240 --> 00:53:42,515 And the computer's not going to like that. 1022 00:53:42,515 --> 00:53:45,630 Yeah, exactly. 1023 00:53:45,630 --> 00:53:46,540 Cool. 1024 00:53:46,540 --> 00:53:47,525 Everyone good? 1025 00:53:47,525 --> 00:53:55,770 1026 00:53:55,770 --> 00:53:59,770 >> And secondly, we're going to go over a function called strstr. 1027 00:53:59,770 --> 00:54:02,020 No worries if these functions are confusing you. 1028 00:54:02,020 --> 00:54:03,750 They're confusing me. 1029 00:54:03,750 --> 00:54:07,250 As such, you guys could have seen, they all sound pretty much the same. 1030 00:54:07,250 --> 00:54:10,400 Just whenever you're confused, pull up the string.h library. 1031 00:54:10,400 --> 00:54:13,290 And you guys can sort through which one's which. 1032 00:54:13,290 --> 00:54:18,910 >> So strstr, all that does is searches a string for a whole other string. 1033 00:54:18,910 --> 00:54:21,980 So where strchr just searches for a single character, 1034 00:54:21,980 --> 00:54:24,090 strstr searches for an entire string. 1035 00:54:24,090 --> 00:54:30,440 So I wanted to look in, I don't know, Hi, my name is Andi. 1036 00:54:30,440 --> 00:54:32,490 And my best friend's name is also Andi. 1037 00:54:32,490 --> 00:54:37,180 >> If I wanted to look for in this sentence for the entire word of Andi, 1038 00:54:37,180 --> 00:54:39,930 my needle would have been whatever you're looking for. 1039 00:54:39,930 --> 00:54:43,440 And your haystack is whatever you're looking for it in. 1040 00:54:43,440 --> 00:54:47,050 So if you're looking for a specific word within a sentence, 1041 00:54:47,050 --> 00:54:48,800 that word is going to be your needle. 1042 00:54:48,800 --> 00:54:51,397 And then the sentence itself is going to be your haystack. 1043 00:54:51,397 --> 00:54:53,230 And so it just searches the first occurrence 1044 00:54:53,230 --> 00:54:55,063 of the string needle in the string haystack. 1045 00:54:55,063 --> 00:54:57,140 It returns the pointer to the first occurrence. 1046 00:54:57,140 --> 00:55:00,510 Except, remember in this case, it's the first occurrence of the entire string 1047 00:55:00,510 --> 00:55:02,510 that you're searching for, not just a character. 1048 00:55:02,510 --> 00:55:04,676 >> And so this is almost the same thing as the function 1049 00:55:04,676 --> 00:55:09,100 we just did, just with a bit more specificity. 1050 00:55:09,100 --> 00:55:12,730 Because you're searching for more than just one character. 1051 00:55:12,730 --> 00:55:16,310 And the usage is the exact same as the one that we just did. 1052 00:55:16,310 --> 00:55:18,070 Everyone OK with this? 1053 00:55:18,070 --> 00:55:20,250 OK. 1054 00:55:20,250 --> 00:55:23,560 >> Last one we're going to go over is strrchr, which is not 1055 00:55:23,560 --> 00:55:26,320 confused with strstr or with strchr. 1056 00:55:26,320 --> 00:55:27,890 strrchr has an extra r in there. 1057 00:55:27,890 --> 00:55:29,140 Be careful when you're typing. 1058 00:55:29,140 --> 00:55:33,851 You may find yourself including an extra r or not including an r, 1059 00:55:33,851 --> 00:55:35,850 and then your function is got not going to work. 1060 00:55:35,850 --> 00:55:37,183 And you're going to be confused. 1061 00:55:37,183 --> 00:55:40,150 Be careful that you're spelling all these functions right. 1062 00:55:40,150 --> 00:55:43,770 >> So strrchr is the exact same thing as strchr 1063 00:55:43,770 --> 00:55:47,480 except it searches for not the first occurrence of a specific character, 1064 00:55:47,480 --> 00:55:49,350 but rather the last occurrence. 1065 00:55:49,350 --> 00:55:52,800 And so, in that sense, it's almost the exact same. 1066 00:55:52,800 --> 00:55:54,620 But instead of moving forward in a string, 1067 00:55:54,620 --> 00:55:57,230 you're going to be moving backwards in a string. 1068 00:55:57,230 --> 00:56:00,510 Exact same thing, you're just searching in a different order. 1069 00:56:00,510 --> 00:56:04,690 >> And so this could be super, super useful for your lookup 1070 00:56:04,690 --> 00:56:07,490 function, the first function on your pset. 1071 00:56:07,490 --> 00:56:12,710 Let's pretend that we needed to write a function of void extension in which we 1072 00:56:12,710 --> 00:56:17,850 pass a constant char* file name, just a string, a file name, 1073 00:56:17,850 --> 00:56:21,370 that takes in that name and prints out the extension of that file. 1074 00:56:21,370 --> 00:56:26,520 So for example, if I were to pass in the string of pset7.zip, 1075 00:56:26,520 --> 00:56:30,004 it's going to print out just the extension, which is .zip. 1076 00:56:30,004 --> 00:56:31,920 And this would work for any sort of extension, 1077 00:56:31,920 --> 00:56:38,290 .docx for Word or .pdf for a PDF file or .html for an HTML file. 1078 00:56:38,290 --> 00:56:40,425 Pretty much, write a function that can do that. 1079 00:56:40,425 --> 00:56:42,300 I'm actually going to switch over to the IDE. 1080 00:56:42,300 --> 00:56:54,560 1081 00:56:54,560 --> 00:56:56,740 It is not load-- there we go. 1082 00:56:56,740 --> 00:57:00,990 >> So all I've done here is created a char*, a first string, 1083 00:57:00,990 --> 00:57:01,930 called pset7.zip. 1084 00:57:01,930 --> 00:57:04,530 I'm going to zoom in. 1085 00:57:04,530 --> 00:57:08,520 I've created a second string called finalpaper.docx. 1086 00:57:08,520 --> 00:57:12,649 And write me a function that when called is going to just print out 1087 00:57:12,649 --> 00:57:13,690 the file name extensions. 1088 00:57:13,690 --> 00:57:16,702 1089 00:57:16,702 --> 00:57:19,660 Maybe take a couple minutes to think about how you're going to do this. 1090 00:57:19,660 --> 00:57:22,510 Slightly more challenging than the last one, 1091 00:57:22,510 --> 00:57:24,770 but the usage is almost exactly the same. 1092 00:57:24,770 --> 00:57:29,670 1093 00:57:29,670 --> 00:57:30,170 Yeah. 1094 00:57:30,170 --> 00:57:37,540 So write a function called extension that, if I give you the name of a file, 1095 00:57:37,540 --> 00:57:41,340 if I were to give you pset7.zip-- I want you to print out just the .zip. 1096 00:57:41,340 --> 00:57:45,040 1097 00:57:45,040 --> 00:57:49,890 If I give you like finalpaper.docx, just print out the .docx, 1098 00:57:49,890 --> 00:57:51,538 just the extension of whatever file. 1099 00:57:51,538 --> 00:59:03,720 1100 00:59:03,720 --> 00:59:07,790 >> This actually only takes two lines of code. 1101 00:59:07,790 --> 00:59:10,692 So try to see if you can maybe do it in that. 1102 00:59:10,692 --> 00:59:12,400 Actually, it only takes one line of code. 1103 00:59:12,400 --> 00:59:14,074 But two lines is probably more standard. 1104 00:59:14,074 --> 00:59:20,408 1105 00:59:20,408 --> 00:59:22,574 What function are we probably going to want to call? 1106 00:59:22,574 --> 00:59:25,286 1107 00:59:25,286 --> 00:59:26,260 >> AUDIENCE: strrchr. 1108 00:59:26,260 --> 00:59:27,343 >> ANDI PENG: strrchr, right. 1109 00:59:27,343 --> 00:59:29,570 Because we're looking from the right left. 1110 00:59:29,570 --> 00:59:32,107 1111 00:59:32,107 --> 00:59:33,940 I didn't give you guys an example like this, 1112 00:59:33,940 --> 00:59:38,870 but if I gave you an example like www.apple.com and I just wanted 1113 00:59:38,870 --> 00:59:43,005 the .com, it'd be a example of where you want to call the last instance 1114 00:59:43,005 --> 00:59:44,630 of the period and not the first, right? 1115 00:59:44,630 --> 00:59:47,470 If you were call strchr, it would've given you the apple.com. 1116 00:59:47,470 --> 00:59:49,966 >> If you called strrchr, it would have given you the .com. 1117 00:59:49,966 --> 00:59:53,062 And so be careful on which ways-- in my example, 1118 00:59:53,062 --> 00:59:55,520 you could probably could have just written it using strchr, 1119 00:59:55,520 --> 00:59:57,130 since there's only one dot. 1120 00:59:57,130 --> 00:59:59,790 But in other instances, that may not be the case. 1121 00:59:59,790 --> 01:00:04,960 And so always try to design your code well, so that-- yeah? 1122 01:00:04,960 --> 01:00:07,365 >> AUDIENCE: So in the example you just said, 1123 01:00:07,365 --> 01:00:11,760 when you do strrchr it would give you .com or just come? 1124 01:00:11,760 --> 01:00:13,960 >> ANDI PENG: It would give you the .com. 1125 01:00:13,960 --> 01:00:14,794 >> AUDIENCE: OK. 1126 01:00:14,794 --> 01:00:15,460 ANDI PENG: Yeah. 1127 01:00:15,460 --> 01:00:18,090 1128 01:00:18,090 --> 01:00:19,744 It points to where it found it. 1129 01:00:19,744 --> 01:00:20,244 Yeah. 1130 01:00:20,244 --> 01:00:24,120 1131 01:00:24,120 --> 01:00:25,188 30 seconds maybe? 1132 01:00:25,188 --> 01:00:25,688 Yeah. 1133 01:00:25,688 --> 01:00:56,640 1134 01:00:56,640 --> 01:00:58,500 Everyone good or maybe a bit more time? 1135 01:00:58,500 --> 01:01:01,057 1136 01:01:01,057 --> 01:01:01,640 Show of hands? 1137 01:01:01,640 --> 01:01:02,320 Show of heads? 1138 01:01:02,320 --> 01:01:04,801 1139 01:01:04,801 --> 01:01:05,300 Cool. 1140 01:01:05,300 --> 01:01:07,924 Anyone want to give me the first line of code for this program? 1141 01:01:07,924 --> 01:01:11,861 1142 01:01:11,861 --> 01:01:12,777 AUDIENCE: [INAUDIBLE]. 1143 01:01:12,777 --> 01:01:16,190 1144 01:01:16,190 --> 01:01:20,160 >> ANDI PENG: So first of all, let's maybe break this down. 1145 01:01:20,160 --> 01:01:24,370 So what is the return type of strrchr? 1146 01:01:24,370 --> 01:01:26,150 Let's go back. 1147 01:01:26,150 --> 01:01:29,015 strrchr, what is the return type? 1148 01:01:29,015 --> 01:01:29,640 AUDIENCE: Char* 1149 01:01:29,640 --> 01:01:31,270 ANDI PENG: It's a char*, right? 1150 01:01:31,270 --> 01:01:35,760 Which means that you're probably going to want to create another char* to kind 1151 01:01:35,760 --> 01:01:40,400 of store whenever it's returning to, right? 1152 01:01:40,400 --> 01:01:43,200 Because if you call the function strrchr, 1153 01:01:43,200 --> 01:01:47,030 it's going to give you a pointer to wherever it found that last period, 1154 01:01:47,030 --> 01:01:47,580 right? 1155 01:01:47,580 --> 01:01:49,913 >> But you're going to want to store that somewhere, right? 1156 01:01:49,913 --> 01:01:52,612 And so how do we code this into our program? 1157 01:01:52,612 --> 01:01:54,320 AUDIENCE: You make the char* [INAUDIBLE]. 1158 01:01:54,320 --> 01:01:55,240 ANDI PENG: Yep. 1159 01:01:55,240 --> 01:01:57,120 AUDIENCE: [INAUDIBLE]. 1160 01:01:57,120 --> 01:01:58,000 ANDI PENG: strrchr. 1161 01:01:58,000 --> 01:01:58,390 Yeah. 1162 01:01:58,390 --> 01:01:59,306 Oh, missed an r there. 1163 01:01:59,306 --> 01:02:02,877 AUDIENCE: File name [INAUDIBLE]. 1164 01:02:02,877 --> 01:02:03,376 What is it? 1165 01:02:03,376 --> 01:02:04,420 Oh, It's just s. 1166 01:02:04,420 --> 01:02:04,940 >> ANDI PENG: Oh, it's just s. 1167 01:02:04,940 --> 01:02:05,610 Yup, sorry. 1168 01:02:05,610 --> 01:02:06,330 My bad. 1169 01:02:06,330 --> 01:02:08,370 Examples did not match. 1170 01:02:08,370 --> 01:02:12,130 >> AUDIENCE: And then dot. 1171 01:02:12,130 --> 01:02:13,970 >> ANDI PENG: Yup. 1172 01:02:13,970 --> 01:02:16,570 Be careful when you guys are-- here, let me zoom in. 1173 01:02:16,570 --> 01:02:22,355 1174 01:02:22,355 --> 01:02:24,400 There we go. 1175 01:02:24,400 --> 01:02:26,770 Be careful when you guys are typing, especially when 1176 01:02:26,770 --> 01:02:27,920 you're doing just a char. 1177 01:02:27,920 --> 01:02:32,480 It's really easy to accidentally just do double quotes rather than single. 1178 01:02:32,480 --> 01:02:35,212 >> That will not work. 1179 01:02:35,212 --> 01:02:36,670 Your compiler is going to complain. 1180 01:02:36,670 --> 01:02:38,790 And your function is just not going to run. 1181 01:02:38,790 --> 01:02:40,540 And so be careful when you're doing things 1182 01:02:40,540 --> 01:02:42,622 with chars that it's single quotes. 1183 01:02:42,622 --> 01:02:44,830 And so does this line of code make sense to everyone? 1184 01:02:44,830 --> 01:02:46,810 We're creating a char* pointer. 1185 01:02:46,810 --> 01:02:50,310 Because strrchr returns something of type pointer. 1186 01:02:50,310 --> 01:02:53,440 >> And so we're going to call strchr on s, which is the string, the file 1187 01:02:53,440 --> 01:02:55,140 name, that we're passing in. 1188 01:02:55,140 --> 01:02:59,750 And we're looking for the last instance of a period, which is 1189 01:02:59,750 --> 01:03:02,200 just the single quote dot single quote. 1190 01:03:02,200 --> 01:03:02,700 Yeah. 1191 01:03:02,700 --> 01:03:05,180 >> AUDIENCE: When do we use double quotes and when do we use single quotes? 1192 01:03:05,180 --> 01:03:05,320 >> ANDI PENG: Yeah. 1193 01:03:05,320 --> 01:03:07,180 So double quotes are always used when you 1194 01:03:07,180 --> 01:03:10,120 have a string of more than just one. 1195 01:03:10,120 --> 01:03:13,070 So if you're doing strstr, which is the one that you 1196 01:03:13,070 --> 01:03:16,320 search a string for string, you would pass it in double quotes. 1197 01:03:16,320 --> 01:03:18,070 But any time it's just a single character, 1198 01:03:18,070 --> 01:03:19,870 you want to do single quotes. 1199 01:03:19,870 --> 01:03:22,880 >> It's a good thing to keep in mind. 1200 01:03:22,880 --> 01:03:25,864 So now that we have our pointer, what do we do with it? 1201 01:03:25,864 --> 01:03:27,780 I'm asking you guys to printing it out, right? 1202 01:03:27,780 --> 01:03:30,940 So [INAUDIBLE], you want to give me the line of code? 1203 01:03:30,940 --> 01:03:31,780 >> AUDIENCE: printf-- 1204 01:03:31,780 --> 01:03:32,446 >> ANDI PENG: Yeah. 1205 01:03:32,446 --> 01:03:35,344 1206 01:03:35,344 --> 01:03:36,843 AUDIENCE: --you need a place holder. 1207 01:03:36,843 --> 01:03:37,340 ANDI PENG: Yup. 1208 01:03:37,340 --> 01:03:38,334 AUDIENCE: Print the place holder. 1209 01:03:38,334 --> 01:03:40,322 I don't know what the place holder is but point to it. 1210 01:03:40,322 --> 01:03:40,819 >> OK. 1211 01:03:40,819 --> 01:03:42,027 Let's skip that for now then. 1212 01:03:42,027 --> 01:03:44,556 AUDIENCE: And then comma-- 1213 01:03:44,556 --> 01:03:45,720 >> ANDI PENG: Pointer, right? 1214 01:03:45,720 --> 01:03:47,970 >> AUDIENCE: Pointer, yup. 1215 01:03:47,970 --> 01:03:51,140 >> ANDI PENG: So kind of a trick question, has to do with pointers and strings 1216 01:03:51,140 --> 01:03:53,130 that we've kind of talked about already. 1217 01:03:53,130 --> 01:03:57,766 What kind of place holder do we need for a pointer for a char*? 1218 01:03:57,766 --> 01:03:59,574 >> AUDIENCE: [INAUDIBLE]. 1219 01:03:59,574 --> 01:04:00,240 ANDI PENG: Yeah. 1220 01:04:00,240 --> 01:04:02,522 It's easier than you guys think it is. 1221 01:04:02,522 --> 01:04:03,230 AUDIENCE: String? 1222 01:04:03,230 --> 01:04:04,730 ANDI PENG: It's just a string, exactly. 1223 01:04:04,730 --> 01:04:06,595 Because remember strings don't really exist. 1224 01:04:06,595 --> 01:04:09,430 A char* is the exact same thing as a string. 1225 01:04:09,430 --> 01:04:14,461 And so really this s is what should have been used all along. 1226 01:04:14,461 --> 01:04:14,960 OK. 1227 01:04:14,960 --> 01:04:17,810 >> Let's see if we can try running this. 1228 01:04:17,810 --> 01:04:19,450 Let's do a make extension. 1229 01:04:19,450 --> 01:04:22,710 1230 01:04:22,710 --> 01:04:23,396 Cool. 1231 01:04:23,396 --> 01:04:28,830 You guys see how I passed in the psset7.zip and the finalpaper.docx, 1232 01:04:28,830 --> 01:04:32,500 and it just prints out the .zip and the .docx? 1233 01:04:32,500 --> 01:04:34,150 Make sense? 1234 01:04:34,150 --> 01:04:36,660 >> OK So I think in your look up function in your pset you're 1235 01:04:36,660 --> 01:04:41,050 going to be asked if the string has a certain ending, 1236 01:04:41,050 --> 01:04:42,800 you have to give a certain error code. 1237 01:04:42,800 --> 01:04:44,820 And so this will be pretty awful. 1238 01:04:44,820 --> 01:04:47,350 Because if you can figure out what the extension is, 1239 01:04:47,350 --> 01:04:49,810 you can then compare that extension to see if it matches up 1240 01:04:49,810 --> 01:04:51,251 with a certain extension. 1241 01:04:51,251 --> 01:04:53,250 And then you can return an error message, right? 1242 01:04:53,250 --> 01:04:53,860 Yeah. 1243 01:04:53,860 --> 01:04:55,370 >> AUDIENCE: So we don't have to add 1 or anything? 1244 01:04:55,370 --> 01:04:56,530 The pointer will go to the-- 1245 01:04:56,530 --> 01:04:56,660 >> ANDI PENG: Nope. 1246 01:04:56,660 --> 01:04:57,530 >> AUDIENCE: --point after it. 1247 01:04:57,530 --> 01:04:58,196 >> ANDI PENG: Yeah. 1248 01:04:58,196 --> 01:05:00,650 It points exactly to where the occurrence was. 1249 01:05:00,650 --> 01:05:04,010 So for example here, we're searching for the period. 1250 01:05:04,010 --> 01:05:06,597 So it's going to return a pointer to the period. 1251 01:05:06,597 --> 01:05:08,930 And then it's going to print out starting at the period. 1252 01:05:08,930 --> 01:05:10,260 >> So you don't need to add 1. 1253 01:05:10,260 --> 01:05:15,000 Although, it's totally fine to, if you're ever unsure, to just kind 1254 01:05:15,000 --> 01:05:16,070 of test it out yourself. 1255 01:05:16,070 --> 01:05:17,590 Build a sample program. 1256 01:05:17,590 --> 01:05:20,240 Test it out yourself and see where it's printing. 1257 01:05:20,240 --> 01:05:23,380 That's also not a bad way to do it. 1258 01:05:23,380 --> 01:05:26,040 >> Cool. 1259 01:05:26,040 --> 01:05:28,880 And that's pretty much all I had for you guys today. 1260 01:05:28,880 --> 01:05:31,440 1261 01:05:31,440 --> 01:05:33,300 We did a lot of pset stuff today. 1262 01:05:33,300 --> 01:05:35,720 So when in doubt, like I said, always look up 1263 01:05:35,720 --> 01:05:37,620 the string.h library for this pset. 1264 01:05:37,620 --> 01:05:40,370 There's going to be a lot of function in there that may be useful. 1265 01:05:40,370 --> 01:05:41,300 Some may not be useful. 1266 01:05:41,300 --> 01:05:42,133 I don't really know. 1267 01:05:42,133 --> 01:05:44,370 Wade through it, there's a whole bunch of them. 1268 01:05:44,370 --> 01:05:49,100 strstr, strchr, strrchr are super, super helpful, as well as 1269 01:05:49,100 --> 01:05:52,080 the strcpys and strcasecmps that we've already used. 1270 01:05:52,080 --> 01:05:56,510 >> It's just lot of messing around with strings, determining if they're equal, 1271 01:05:56,510 --> 01:05:59,960 getting stuff out of strings, and being able to open files correctly. 1272 01:05:59,960 --> 01:06:02,252 It's a lot of file I/O. pset's really not that bad. 1273 01:06:02,252 --> 01:06:04,210 You're going to take a look at it, download it, 1274 01:06:04,210 --> 01:06:05,590 and see a whole bunch of code. 1275 01:06:05,590 --> 01:06:09,220 No worries, the code you actually write is not bad at all. 1276 01:06:09,220 --> 01:06:12,870 If anyone has issues with their server, come see me after section. 1277 01:06:12,870 --> 01:06:16,040 >> Apologize once again for not bringing candy to Halloween. 1278 01:06:16,040 --> 01:06:18,790 I don't know what was wrong with me. 1279 01:06:18,790 --> 01:06:20,800 But we will have double the candy next time. 1280 01:06:20,800 --> 01:06:25,620 And good luck in your pset this week. 1281 01:06:25,620 --> 01:06:27,170 Yup. 1282 01:06:27,170 --> 01:06:28,722