WEBVTT 1 00:00:02.159 --> 00:00:14.160 William Cheng: Welcome to the second week discussion section. So I'm going to continue to talk a little about a little bit about warm up one. So by now you should be done with the first part, you will be working on the second part. 2 00:00:14.820 --> 00:00:20.940 William Cheng: So I guess. Today I'm going to sort of talk a little bit about, you know, writing the the source the source command. 3 00:00:22.800 --> 00:00:32.760 William Cheng: Alright, so I guess list has that's for the first part. And I guess what's what's really important is to run the GDP assignment number one. 4 00:00:33.330 --> 00:00:40.140 William Cheng: So again, what's important is to draw a picture and then try to sort of, you know, fill in all the data structure with your addresses. 5 00:00:40.530 --> 00:00:48.660 William Cheng: And, you know, run things under GDP print all the values out and then get used to looking at addresses using hexadecimal numbers. 6 00:00:49.320 --> 00:01:00.000 William Cheng: So this way you will draw your picture and then you, you know, sort of, so look at the content over these data structure and try to sort of convince yourself that you know the picture that you draw the DN looks like a circular circular 7 00:01:00.660 --> 00:01:07.620 William Cheng: web links are to us. Okay, so, so, so, so, again, it's very, very important to understand exactly what a pointer is 8 00:01:07.860 --> 00:01:17.370 William Cheng: A pointer is simply a four by number that contains an address. Okay. And the way we draw a pointer is which, you know, which are big dot there. And then we have a point to something 9 00:01:18.090 --> 00:01:28.380 William Cheng: Alright, so you need to make the connection between what you see inside the data structure inside DDB and what it but you know and then we'll and also what will you see a picture of a link lists, you know, what is the correspondence 10 00:01:28.830 --> 00:01:34.920 William Cheng: But what's between what's going on in memory and also what you see on a piece of paper. Okay, so again, very, very important exercise. Right. 11 00:01:35.550 --> 00:01:51.270 William Cheng: Will you continue with the semester, will you keep keep doing other programming assignments once in a while, you have to draw pictures. Okay, so make sure you understand, you know, the picture with their corresponding the memory location and the content of all these memory locations. Right. 12 00:01:53.910 --> 00:02:02.100 William Cheng: Alright, so before we go to the second part, I just want to sort of briefly review what are the see string functions. So, 13 00:02:02.550 --> 00:02:12.960 William Cheng: If you look at the warm up on FAQ they show the show you a bunch of a C string manipulation function. I mean, some of them are don't even sort of, you know, don't assume that the input is a string. 14 00:02:13.560 --> 00:02:20.580 William Cheng: So, for example, the first one over here as memory compare you compare two addresses. Right. So if you get the idea. Over here is I have 15 00:02:20.910 --> 00:02:28.620 William Cheng: You know, an array of characters. And here's another real characters. I'm going to sort of compare all these memory location over here to make sure that they're exactly the same. 16 00:02:29.190 --> 00:02:38.760 William Cheng: Okay, so in this case the first argument over here is a source string. And the second one is a destination stream and to come as a number of bytes. You want to verify that have exactly the same content. Okay. 17 00:02:39.120 --> 00:02:47.610 William Cheng: So in this case, it will call them compare and the other one is called mem copy you copy from the source to the destination this many number of bytes and what's important. 18 00:02:48.420 --> 00:02:58.080 William Cheng: For you to make sure is that the destination over here, this is the base address of an array. So you got to make sure that the race big enough erase that big, the big enough. You're going to end up with 19 00:02:58.440 --> 00:03:04.830 William Cheng: buffer overflow and going to end up corrupt your program memory. Okay, so, so anyway, so there's a lot of function like this. 20 00:03:05.310 --> 00:03:11.250 William Cheng: This list is in the warm up on FAQ, and also to mention that, you know, this is the function that we have, you know, Colonel assignment. 21 00:03:11.790 --> 00:03:18.900 William Cheng: So therefore, if these functions are enough for the Colonel. Well, then it should be enough for everybody else. Okay. So, therefore, you know, if you want to learn 22 00:03:19.710 --> 00:03:29.190 William Cheng: You know, so, so if you know a little bit about c++ and you were a little about see one of the important things is that in C Plus Plus there's something called a string and in see there's something called see string. 23 00:03:29.850 --> 00:03:36.750 William Cheng: So you need to learn all the things about see stream, because they are not, you know, because people don't don't normally use them in c++ 24 00:03:37.740 --> 00:03:45.150 William Cheng: So in that case, here's just a list of all the function that you need to understand how they work. Right. You don't have to use all of them, but you need to know what they do, as sort of briefly go over at 25 00:03:45.720 --> 00:03:49.710 William Cheng: Here is a string compare. So get string n computer computer up to n character. 26 00:03:50.130 --> 00:03:57.480 William Cheng: The stream company over here and then it will assume that both the source and the destination. They are see streams and that means that they are terminated by the backslash zero character. 27 00:03:57.930 --> 00:04:00.450 William Cheng: Okay. So in this case, you can actually compare them. Alright. 28 00:04:01.350 --> 00:04:12.090 William Cheng: The next one over here is is called string copy. I'm going to copy the source run into the desk us from the source into the destination. So again, I'm going to assume that the source is that no terminated, you know, see string. 29 00:04:12.570 --> 00:04:15.210 William Cheng: So therefore, we try to copy it knows where you did. 30 00:04:15.660 --> 00:04:26.340 William Cheng: It exactly what stop. Okay. Some people will use this card that you use this particular function to copy data. They are not see strings was in that case, you're asking for trouble. 31 00:04:26.760 --> 00:04:33.450 William Cheng: Okay, so therefore don't use that if you don't know that you're dealing with. See strings. Okay. You get to choose which ones you want to use. Yeah. 32 00:04:34.170 --> 00:04:41.880 William Cheng: The next one is go string and copy, we saw that before. So this one cut a copy up to the size of the buffer. So again, you need to know what the size of the buffer is 33 00:04:42.420 --> 00:04:58.800 William Cheng: The necklace meme said, we saw that before. Here is a database address, which is the first address have an array and then you tried to set the standard array, the entire array to be the same value. So in this case, the second argument over here is the 34 00:04:59.850 --> 00:05:05.850 William Cheng: Is the integer. Okay. So, typically the way we sort of think about is that we have array of characters. We've had to set up all to the same pattern. 35 00:05:06.360 --> 00:05:10.560 William Cheng: So even though the second argument as an integer, which is always also only think about it as a single bite. 36 00:05:10.830 --> 00:05:19.440 William Cheng: Okay. And the last argument of here tell you how many. What is the size of the buffer and they will set every bite into the pattern that specify in the second argument. 37 00:05:20.130 --> 00:05:24.750 William Cheng: So yeah, if you don't know what is the function. It should look at the main page where I used to say, man. 38 00:05:25.350 --> 00:05:32.550 William Cheng: Followed by you know the name of the function, and he will show you what the function does guys. So if you have any questions about these function, you know, 39 00:05:33.180 --> 00:05:34.050 William Cheng: Feel free to send me email. 40 00:05:34.620 --> 00:05:42.120 William Cheng: And this is weird functional. I never seen this one before. So I'm going to skip this one, and that's why it's called string length. Right. Given a string to tell me how many bites. 41 00:05:42.330 --> 00:05:47.220 William Cheng: Are in the string. It doesn't count the backside zero character or the know character at the yet. Okay. 42 00:05:47.760 --> 00:05:59.820 William Cheng: String char. We're going to see that how to use that the other day. So this is like a search function. Given a string or they tried to look for a particular character. Again, this particular character over here. It's an integer, but we only look at that bite to look for a particular pattern. 43 00:06:01.500 --> 00:06:11.340 William Cheng: String are char. Look at the stream from the reverse direction so i. So, if you have a stream like this in the end terminated with the backside zero string are charged search for the character, starting from the back. 44 00:06:11.730 --> 00:06:15.720 William Cheng: Okay stream charts searching from the front. So these are pretty useful function. 45 00:06:16.170 --> 00:06:22.470 William Cheng: String string is to look for sub strings that are streaming. Right. So over here, there's a string over here, you can look for, you know, x, y, and z. 46 00:06:22.920 --> 00:06:30.090 William Cheng: put this into a string and then it will look for it string cat. Be very careful with this function. So this try to concatenate 47 00:06:30.570 --> 00:06:38.520 William Cheng: The source into the destination. Right. So the destination over here is going to be a string, it will look for the end and then it will copy string by a pending it to the 48 00:06:39.780 --> 00:06:48.330 William Cheng: To the first argument. Okay, so the first argument if the buffer is not big enough why in this case you again, you're going to end up with buffer overflow, you're going to end up with memory corruption. 49 00:06:48.690 --> 00:06:54.810 William Cheng: So be very, very careful with a function of my stream cat. Yeah. The last one over the other. The next one of us go string dupe 50 00:06:55.260 --> 00:07:03.180 William Cheng: Start with a C Street what he would do that, it will actually call Malik allocate a new string and copy the data from the source into the return value over here. 51 00:07:03.600 --> 00:07:10.440 William Cheng: Yeah, so this why involved Malik, so. So in the end, when you're done with the stream over here, you need to call free at free up memory. 52 00:07:11.340 --> 00:07:19.980 William Cheng: Yeah. The next one is called string toke, this is a very tricky function. And so, I strongly recommend you not to use it unless you really know what you're doing. Okay. 53 00:07:20.520 --> 00:07:24.210 William Cheng: The most important things that was string tone is that you need to be very, very careful when you try to 54 00:07:24.690 --> 00:07:32.400 William Cheng: Try to, you know, try to use string Tolkien one function and then you use another function to clustering talk again and these two functions are nested together. 55 00:07:32.940 --> 00:07:37.260 William Cheng: Okay, so in that case you should be very, very careful with strings hope because if you are not very careful. 56 00:07:37.860 --> 00:07:46.920 William Cheng: You're going to end up with really, really bad results. Okay, so try not to use it if you want to use it only use it at one level and don't use the internet to function. Okay. 57 00:07:47.850 --> 00:08:01.830 William Cheng: All right, yeah. Some people find this function on the internet that was trying to use it because we're supposed to do parsing of the industry. So if you try to parse some something some strange. Some people will use string to to look for the tap character. Again, be very careful. Yeah. 58 00:08:02.880 --> 00:08:10.110 William Cheng: So, so how do you be very, very careful. Right. You read the you read the main page of stream tone and you tried to fully understand exactly what's telling you 59 00:08:10.620 --> 00:08:13.650 William Cheng: Okay, if anything, you don't understand. You can send me email. Yeah. 60 00:08:14.250 --> 00:08:22.260 William Cheng: So these are the basic see stream manipulating function. Other things you have to learn is F gets you are. You do that in warm up one. So you need to get familiar with reading 61 00:08:22.500 --> 00:08:26.760 William Cheng: Reading a stream on the input. So again, if you have questions, and the email and the otherwise print off. 62 00:08:27.150 --> 00:08:34.350 William Cheng: That's for output right f f gadgets for inputting one line at a time. So printed. You know, you try to print stuff you know into standard out 63 00:08:34.800 --> 00:08:42.690 William Cheng: So again, this is the function, you need to get familiar with. Okay. All right. So these are the basic you know see function, you need to get familiar with, you know, before you proceed. 64 00:08:44.310 --> 00:08:54.210 William Cheng: Alright, so the part B of the world one so you can read the grading guidelines and read the spec right to sort command which you will do that you will read a bunch of input. 65 00:08:54.510 --> 00:09:05.220 William Cheng: You know, so, so you will take the input file, you try to read one line at a time, every line you parse it into four fields. One of them is a timestamp and then you validate entire line. I think I post the 66 00:09:06.300 --> 00:09:09.090 William Cheng: There's a, there's a one one FAQ tell you how to actually do that. 67 00:09:09.390 --> 00:09:16.470 William Cheng: Okay. And then when you finish parsing that you need to create a transaction data structure and you fill the transaction data structure with the information on that line. 68 00:09:16.650 --> 00:09:26.730 William Cheng: And then you add a transaction on the you got a transaction object or a data structure into a list right and the end you sort the list and then you print them out. According to the timestamp. 69 00:09:27.270 --> 00:09:35.460 William Cheng: Okay, so that's what your warm up that you know that that's what you're supposed to do. So here is basically the pseudo code for it. 70 00:09:36.210 --> 00:09:39.720 William Cheng: Okay, you create a list over here initially as a list to be empty list. 71 00:09:39.960 --> 00:09:49.470 William Cheng: And then you read the input and you pass the list as an argument into this function. So the idea here is that will you read the input you parse every line and then you create the object you append that to this list. 72 00:09:49.740 --> 00:09:55.920 William Cheng: When you're done with this you close the input. Right. And then you call a function to sort the limp of the employer. When will you finish starting and 73 00:09:56.340 --> 00:10:05.970 William Cheng: Then you and then and then in this case you print your transaction, the premier bank statement by, you know, by by by by by putting out this list. 74 00:10:06.690 --> 00:10:17.310 William Cheng: OK. So the top level pseudo code for your warm up. I should be very, very simple. Okay. So the idea here is that you need to get used to reading your program by writing small functions and then put them together to 75 00:10:17.640 --> 00:10:24.600 William Cheng: To to create larger function and then do your main program basically all it does the call want to, you know, call several these functions and then you're done. 76 00:10:25.410 --> 00:10:29.910 William Cheng: Okay, so every function is I guess if you sort of, you know, follow some of the software engineering practices. 77 00:10:30.150 --> 00:10:37.080 William Cheng: Every function, you should be you know 1020 lines. I mean 20 lines is actually pretty big. Right. Some people will actually use a smaller number. So it again depends on your taste. 78 00:10:37.410 --> 00:10:46.920 William Cheng: I just want to remind you that when we. Great. We don't really care about these kind of style. The DVD style issues, you're not going to lose any points if you put all your, you know, functionality in a really, really big program. 79 00:10:47.520 --> 00:10:55.470 William Cheng: Okay, but it's a good practice to learn how to write program correctly by writing all these small functions and they have the larger function called smaller functions. Now, 80 00:10:56.250 --> 00:11:04.560 William Cheng: Alright, so we're going to, sort of, you know, show you some code, how to read input, how to parse sort over here. You already know how to sort right because the list test. I see. 81 00:11:04.740 --> 00:11:12.390 William Cheng: Give you a bubble. So programs, you can just adapt that bubble sore. So the bubble. So program. Try to try to solve the object based on the value of the object. 82 00:11:12.750 --> 00:11:26.220 William Cheng: So you just need to modify the code a little bit so they can actually store that based on the timestamp. Okay, so, so, so, so again if you have questions about that, feel free to send me an email. Right. Oh, by the way. And the last one over the years as try to practice them in 83 00:11:28.530 --> 00:11:33.540 William Cheng: The warm up one spec tells you what the statement supposed to look like. So you just want to make sure that everything lines up carefully. 84 00:11:34.080 --> 00:11:43.080 William Cheng: So again, I mean, some people complain that this is really tedious and this is a practice programming assignment to get you good at, you know, placing things exactly where you are writing, you know, 85 00:11:43.410 --> 00:11:54.030 William Cheng: A program, you know, basically, is is a lot of practice and you need to be able to control exactly how you read input. You need to be able to control exactly where we're things. Want to go on the cocoa and the print out 86 00:11:54.630 --> 00:12:03.870 William Cheng: Once you get good at it, you know, then things should be a lot easier. Okay. So even though things are a little tedious. I think these are really, really good exercise for you to understand exactly what your code is doing. 87 00:12:04.560 --> 00:12:10.110 William Cheng: Okay, what you need to make sure is that every line of code that you write, you know exactly what everyone is doing. 88 00:12:10.590 --> 00:12:21.930 William Cheng: OK, so don't copy stuff on the internet because the internet, say, oh, it works on the internet. So, therefore, is going to work in the microbiome, don't do that. Okay, make sure you understand every line of code every line of your code. 89 00:12:22.530 --> 00:12:35.490 William Cheng: Okay, so this way you will you know you this way you are. You India, you can master programming. Okay. That will be the goal is that we need to get really, really good at programming that 90 00:12:36.270 --> 00:12:40.110 William Cheng: Alright, so don't don't take any shortcut, you know, try to understand everything that you write 91 00:12:40.890 --> 00:12:51.360 William Cheng: All right, to read a line right we use this function f gets above the size of the above what we hear people I guess somebody, somebody just asked me to in today's, you know, live lectures and why do we use 1026 92 00:12:51.930 --> 00:12:56.640 William Cheng: You know, because the the spec says the longest last 1024 and then that include the 93 00:12:57.540 --> 00:13:05.580 William Cheng: I can't remember what the specs us now. Does it include the backside zero or not. But the idea here is that, you know, you can always use a BLEEP you use a big about her. If you're in doubt. 94 00:13:05.880 --> 00:13:14.190 William Cheng: Okay, so this way I can actually use buffer over here 2000 right so in this case the line that I read can be really, really long. And as soon as I read it, I can check with the line. 95 00:13:14.370 --> 00:13:18.990 William Cheng: is longer than the spec you the last longer than the spec a printer and error message and quit my program right away. 96 00:13:20.070 --> 00:13:32.430 William Cheng: Okay, so the number of here, it doesn't really matter. You just need to make sure that it's big enough. OK, I will use something bigger, you know you. If you're not sure where these us 1024 2526 might as well use a much bigger number. Yeah. 97 00:13:33.330 --> 00:13:41.160 William Cheng: Right, and then you need to parse ly according to the spec. Right. So. So one might know my recommendation is to write, you know, write something simple. 98 00:13:41.400 --> 00:13:48.780 William Cheng: Right. Something you perfectly understand write something that you can verify that you have no bug in your code. Okay, that's the kind of program issue right 99 00:13:49.260 --> 00:13:54.870 William Cheng: Okay, some people say, oh, I want to run that Run my code in the most compact way. There's no such requirement. Don't do that. 100 00:13:55.740 --> 00:14:02.940 William Cheng: Okay, don't try to find ways that that will make your program, nice and short and you don't understand what are you doing okay so that would be a really, really bad way to go. 101 00:14:03.660 --> 00:14:09.300 William Cheng: Okay, so, so, so therefore you know what you should do is that, you know, right, tiny function that you know exactly what is tiny function will do 102 00:14:09.510 --> 00:14:15.630 William Cheng: And then write another function, I will call this function. So, since you know what those tiny functions going to do well, then you should know what the bigger function will do 103 00:14:16.860 --> 00:14:26.460 William Cheng: Okay, so some people will say that why you know when whenever you try to write a function over here right above it, you should put a comment blog to say what this function does. Okay. And you write the precondition Reddit post condition. 104 00:14:27.000 --> 00:14:32.520 William Cheng: So the precondition is that you know is what it means is that it's a fancy word, will you come inside this function. What do you assume 105 00:14:34.080 --> 00:14:40.560 William Cheng: Okay, so if you know if this particular who's got a sort of list. Why should I assume. Well, maybe I should assume that the list is a valid list. 106 00:14:40.920 --> 00:14:44.220 William Cheng: Right, because if the list is not a valid as well then why am I sorting it 107 00:14:44.790 --> 00:14:51.840 William Cheng: Okay, so therefore, these other sort of the precondition. What do you assume when you when you enter the function, the post condition is that with this function return what happened. 108 00:14:52.740 --> 00:15:06.720 William Cheng: Okay, so if you are thinking about my for to lift a pen. Right. Why did the post condition is that, you know, when you enter the will we enter this function that the length of the list is x. So, therefore, when you return for this function what the length of the list up x plus one. 109 00:15:08.190 --> 00:15:19.320 William Cheng: Okay, so some of those, you know, sort of the post engine that actually pretty straightforward. And also, when I returned from this function, the list still continue to add to be a valid list right because I want to make sure that my program doesn't destroy the list. 110 00:15:20.340 --> 00:15:29.580 William Cheng: Right. So when you write your function, you should write a comment blog right in front of their spells out exactly what this function assume, and also what the function does. Right. So once you get used to this. You'll get you 111 00:15:30.330 --> 00:15:39.780 William Cheng: You're going to get much better programming now alright so again the message will be here is that, make sure that your code is correct and don't try to look for shortcuts that you don't understand what's going on. Okay. 112 00:15:41.370 --> 00:15:55.230 William Cheng: Okay, so. So according to the spec. You know, every liner input must contain at least site must contain exactly three tab characters, right, if the line doesn't contain contain three characters, then you just give up. You said you know the implant is wrong. 113 00:15:55.680 --> 00:16:02.640 William Cheng: Okay, so how do you look for tat character. I just mentioned that there's one function, you can use. It's called string char right st RC HR 114 00:16:02.880 --> 00:16:11.190 William Cheng: Given a see string, right. So again, the precondition is that the first argument over here is a string. What if it's not a string. Well, then don't use this function. 115 00:16:12.720 --> 00:16:17.670 William Cheng: Okay, so you so it's your responsibility to make sure that the first argument over here is a string. 116 00:16:17.970 --> 00:16:22.800 William Cheng: Okay, because otherwise this function is going to produce onyx, you know, unexpected results. Okay. 117 00:16:23.100 --> 00:16:30.360 William Cheng: All right. The second argument over here is this is the character, you need to look for. So if you want to look for the tab character or you have to do is to say, I want to look for the top character. 118 00:16:30.780 --> 00:16:42.030 William Cheng: Measuring these you're going to see this function over here the buffer is the buffer that I read from F gets and when f gets returned it guarantee to give you a see stream. Right. That's how I know that the the bubble over here will be a string. 119 00:16:42.600 --> 00:16:53.400 William Cheng: Yeah. And then I can use the screenshot functioning to start with the the the buffer point over here and try to look for tab so so you should draw a picture right here is my buffer my buffers right here. Yeah. 120 00:16:53.640 --> 00:17:04.920 William Cheng: And then I use a pointer to point to it. OK, so now I'm going to start from the beginning. Over here, I'm going to look for backslash t. So, therefore, when this function returns successfully the tab pointer over here will point to this character. 121 00:17:06.540 --> 00:17:14.880 William Cheng: OK. So again, it's very, very important to understand the nature of pointer. So that when you write code like this, you can draw a picture like this and you know exactly what the picture means 122 00:17:15.150 --> 00:17:19.320 William Cheng: And also, if you are in the debugger. You can print out all these addresses and they will make sense. 123 00:17:20.550 --> 00:17:24.870 William Cheng: If you put the all these things together, you're going to end up with a picture that looks like this. 124 00:17:25.830 --> 00:17:30.690 William Cheng: OK. So, again, very, very important to go through this exercise so you know exactly what you're looking at. Okay. 125 00:17:31.050 --> 00:17:41.820 William Cheng: All right, so it is possible. This particular function will return. Now that means that it cannot find a tab character. So if the type of a pointer over here is not equal to know what that means that this pointer over here, point to attack character. 126 00:17:42.570 --> 00:17:55.530 William Cheng: Okay, so they have a wallet can do is I can replace it with a zero character with a new character. So this one I will change it into a backside zero right when I do that, and you can as soon as we look at the memory location right here. Now I end up with the see string. 127 00:17:56.820 --> 00:18:08.250 William Cheng: Okay. So in this case, what were the see screenshot this Easter. We'll start with buffer and then it will end with a batch of zero character. So therefore, by writing this code, you can actually create additional see string starting out with a string. 128 00:18:09.360 --> 00:18:19.590 William Cheng: OK, so the gold over here is that, you know, if I start with a, you know, if I start with a buffer, which is the sea string and I have three tap characters. I need to chop them into foresee strings. Each one of them correspond to a field. 129 00:18:20.670 --> 00:18:29.820 William Cheng: Okay, so therefore, in this case, you know. Yeah. So, so why do you understand exactly what it's called. It's doing. You can do this four times. Or you can do the three times and then they can end up with 130 00:18:31.170 --> 00:18:34.230 William Cheng: You can end up with four see strings. Yeah. 131 00:18:35.820 --> 00:18:45.840 William Cheng: Alright, so over here. So to show you what the picture look like, right. So, now listen I read a line over here instead of buffer content is character, a BBC tab space D tab f 132 00:18:46.560 --> 00:18:50.820 William Cheng: 00 right we have multiple zeros. But again, the Eastern star at the, you know, 133 00:18:51.150 --> 00:19:04.620 William Cheng: The see string. And at first, zero. So as far as my sister is concerned, it only ends right here. Right. And then the last, the last zero. I don't really care about it. Yeah. Alright. So in this case, keep disappearing on me. I don't know what's going on. 134 00:19:06.300 --> 00:19:13.050 William Cheng: There. Alright, so in this case over here. I only have two tabs. Right. So, therefore, you know that you need to create an error message. In the end, right. So, therefore, we are 135 00:19:13.260 --> 00:19:15.450 William Cheng: Going to sort of walk through this code and see what it does. 136 00:19:15.660 --> 00:19:23.760 William Cheng: And in the end, if you keep doing this you want. You will only find two tabs and the last one over here. He said, I cannot find a third tab so therefore you print an error message and quit your program. 137 00:19:24.060 --> 00:19:33.030 William Cheng: Well, so again, what error message would you would you print. Well, I mean, you know, if you cannot find the third tabs you can conclude that this line doesn't have three tabs. 138 00:19:33.390 --> 00:19:40.950 William Cheng: Right, so therefore you're measuring your error message should be line number, you know, whatever the line number is line number seven line number seven does not have three taps. 139 00:19:41.520 --> 00:19:42.660 William Cheng: Is that a good error message. 140 00:19:43.560 --> 00:19:53.070 William Cheng: Well, so, so again if you pretend that you're a user running your own program right and then you know your program dies and said that you know line seven only has two, you know, does not have three tabs. 141 00:19:53.250 --> 00:20:03.300 William Cheng: Well, then, in this case, you know exactly what to do right you open your file. Go to line seven count the number of tab. And sure enough, it doesn't have three right so if we can actually use that error message to fix the input. 142 00:20:04.380 --> 00:20:07.800 William Cheng: Okay, if my error messages that input is Mel form. I mean, is that 143 00:20:09.510 --> 00:20:18.690 William Cheng: Is that actually useful for the user, or it's not very, very useful because because if your input file is 1 million lines long. And you say the inputs malformed, well, what does the user going to do 144 00:20:19.710 --> 00:20:21.030 William Cheng: You know, the, the users are luck. 145 00:20:21.570 --> 00:20:31.740 William Cheng: Okay, so therefore we ensure the printer error message you're trying to help the user that requirement if you read the grading down. It's very, very carefully the requirement is that you need to give a user a helpful error message. 146 00:20:32.100 --> 00:20:36.420 William Cheng: Okay, if you're if you error message is not very, very helpful, you can end up losing points. 147 00:20:37.260 --> 00:20:43.320 William Cheng: Okay, so, so again, write your code and then when you encounter error message. Try to get a very, very good error message. 148 00:20:43.680 --> 00:20:53.910 William Cheng: There is one of the requirement is that you know is that if you're parsing the input if you know one of the line is wrong. Well, then you should you should print the line number, right, because otherwise, otherwise you error message is not very, very useful. 149 00:20:54.840 --> 00:21:01.350 William Cheng: Okay, so you need to keep track of the line number. So this way you could give a very helpful message. Yeah. Anyways, that's beside the point here. 150 00:21:02.040 --> 00:21:07.530 William Cheng: Okay, so let's take a look at this picture over here you have a buffer right here, star point or equal to buffer right here is a star pointer. 151 00:21:07.770 --> 00:21:16.470 William Cheng: This one is a character pointer is four bytes long is stored in address. So when you say that equal to buffer, you take the address of the buffer. And then you put that into star pointer. Okay. 152 00:21:16.650 --> 00:21:20.490 William Cheng: Again pictorial we will we will join that will draw that. This one will point out here. 153 00:21:20.880 --> 00:21:27.630 William Cheng: Okay. And again, the red arrow over here signify the IP inside the x86 CPU telling you which instruction, we're executing 154 00:21:28.020 --> 00:21:35.100 William Cheng: Yeah. Alright. So if we're actually the same structure and the, the end result is that the start point over here will point above, so it will look like this. 155 00:21:36.030 --> 00:21:38.250 William Cheng: Then now we go to the next instruction over here. 156 00:21:38.760 --> 00:21:50.310 William Cheng: Tab pointer over here is going to be string charge star pointer stop pointer over here, points to this one. Is this the see string. Yes, it's a shoestring because the Terminator, the backside zero. I'm going to look for the tap character, starting with 157 00:21:50.940 --> 00:21:54.210 William Cheng: You know, with the top pointer over here. So I'm going to start right here. I'm going to look for 158 00:21:54.390 --> 00:22:04.620 William Cheng: You know this character. So when I'm done over here the you know the tap point your point right here. Right. So here's the top pointer. Again, it's a point of data structure. It has four bytes, a content and address 159 00:22:05.040 --> 00:22:10.380 William Cheng: So the way we sort of draw the picture of containing addresses that will draw a pointer over here pointed this memory location. 160 00:22:11.130 --> 00:22:14.310 William Cheng: Okay, so therefore, when this instruction is finished executing it will look like this. 161 00:22:15.120 --> 00:22:22.080 William Cheng: Then alright the next instruction over here it says tab pointer is equal to now. So get a null pointer is just zero. Right. 162 00:22:22.290 --> 00:22:31.080 William Cheng: We're going to take this top pointer over here, look at the content of the top pointer to say, does it equal to zero. I mean, clearly, this one is equal to zero because it contains a valid address 163 00:22:31.350 --> 00:22:35.790 William Cheng: Okay, so definitely this guy's you will be not equal to zero, right. So I'm going to go to the next instruction over here. 164 00:22:36.030 --> 00:22:45.540 William Cheng: This one says star pointer equals zero. Start pointer. So, so, by the way, whenever you see star followed by pointer is as follows the pointer towards pointing it and then do something there. 165 00:22:46.050 --> 00:22:53.520 William Cheng: Okay so so top point over here is the pointer star says, Follow the pointer over here, the words pointing to. So what is the point to 166 00:22:54.240 --> 00:23:00.540 William Cheng: That tab point over here is a pointer to characters, always a start point over here, you're pointing to a character. 167 00:23:00.840 --> 00:23:12.240 William Cheng: Okay, okay, you're pointing to a single bite right so here's the say sit that single by to a backside zero. So, you follow the part over here and then change this one to a backside zero okay and then this one also says, plus, plus. 168 00:23:13.140 --> 00:23:18.690 William Cheng: So, so, so, so you see what he says, A plus plus. That means that I'm going to increment this particular object. 169 00:23:19.350 --> 00:23:23.880 William Cheng: Okay. Tap pointer over here now pointed this one, right, so remember tab partner is an address. 170 00:23:24.180 --> 00:23:29.610 William Cheng: Okay, so plus plus over here is I'm going to increment the address by one. Okay, why do I want to buy one. 171 00:23:29.910 --> 00:23:40.320 William Cheng: Because this one is appointed to a character and the character is one bite in size. So therefore, in this case, when I finished doing that the top point over here will point to the next character. And then over here will be replaced by zero. 172 00:23:41.010 --> 00:23:48.780 William Cheng: There. So therefore, when I'm done, they will look like this. This one I replaced by zero. And then I'm going to increment attack pointed to the next character. 173 00:23:50.400 --> 00:23:55.770 William Cheng: So in simpler. You see there's another way to do it. You can say plus plus star pointer over here. 174 00:23:56.070 --> 00:24:04.830 William Cheng: There. So this one again this is equal to backslash zero over here. So if people plus plus in front of it. That means that I need to increment the point of first. Sorry. 175 00:24:05.790 --> 00:24:22.890 William Cheng: Okay, it's star plus plus pointer. Okay gotta be very careful with see over here, is it back to zero. Okay, so if you do that, what it will do is that it will increment the pointer first to point it over here and then replaced by zero. Okay, so again, in the previous example over here. 176 00:24:24.060 --> 00:24:31.770 William Cheng: Okay, if you change this code to be star plus plus pointer. Okay, equals to pack size zero 177 00:24:32.070 --> 00:24:40.770 William Cheng: Right, then what you will do is that he will increment the pointer first change this point over here. The point of this one and then replace it with a zero. So, this will be turning to zero. And that's not what you want. 178 00:24:41.550 --> 00:24:49.170 William Cheng: Okay, so again you need to know exactly why you're doing things. Certain Way to put plus plus before that the pointer or after the pointer at the result be different. 179 00:24:49.830 --> 00:25:00.150 William Cheng: Okay, so in this case is you want to replace the tap character by zero. Okay. So in this case, you have to go this way. Okay, if you write going the other way, you're gonna end up with something you don't want. Yeah, right. 180 00:25:01.200 --> 00:25:08.040 William Cheng: So when you finish doing that over here. So let's say that if I put this thing on in a loop. Right. And the next time you know the next time I 181 00:25:08.460 --> 00:25:14.010 William Cheng: Come over here. So the goal of yours to take my input and then parse them into foresee strings. 182 00:25:14.880 --> 00:25:19.020 William Cheng: Okay. So in this case, you know, how do I parson. The next the string. I will use exactly the same code. 183 00:25:19.530 --> 00:25:25.680 William Cheng: Okay. So, therefore, what I can do is that I could start with this code and just copy this code and then run it run the three times. 184 00:25:25.950 --> 00:25:31.590 William Cheng: And then in this case I'm going to end up with four string. But again, I need to change my color a little bit in order for it to work. Because right now. 185 00:25:31.830 --> 00:25:39.480 William Cheng: You know, a top pointer is pointing right here and stop on her is pointing right here. So next time we should have stopped part ago right the star pointers you point to 186 00:25:39.840 --> 00:25:43.830 William Cheng: You know, so again, the first screen over here is going to be pointed to buy the star pointer. 187 00:25:44.700 --> 00:26:00.270 William Cheng: Okay, so in this so so so at the end of this operation over here, what I should do is that, you know, maybe I should actually create for pointers of a hero, a call and feel one feel to feel free feel for, so I will say field FR e LD one is equal to tap water. 188 00:26:02.070 --> 00:26:02.580 William Cheng: Tap water. 189 00:26:03.810 --> 00:26:04.140 William Cheng: Sorry. 190 00:26:05.730 --> 00:26:07.050 William Cheng: Let me back it out over here. 191 00:26:10.050 --> 00:26:16.350 William Cheng: Okay, I'm sure. Look at my own picture, right. So where's the one right feel one is actually right here. So feel one over here as you go to start pointer. 192 00:26:20.550 --> 00:26:27.120 William Cheng: Okay, so. So, what I want is that fear one will apply right here where she feel to point to right field to SharePoint right here. Right. 193 00:26:27.330 --> 00:26:39.930 William Cheng: Feel three should point right here because I need to replace all these tab characters over here with a zero. So, feel to is here. It feels three this year. Right. So in this case, it will it will fail because I only find to tap pointers. 194 00:26:41.580 --> 00:26:47.490 William Cheng: Alright, so again you know once you understand how this code where you can write additional co so that you can actually do. You're going to end up with four fields. Okay. 195 00:26:48.330 --> 00:26:53.850 William Cheng: Alright, so now I will say stop whining, you go to tap on there because I point to a point to the beginning of the next field. 196 00:26:54.300 --> 00:26:58.800 William Cheng: Okay, so therefore I was a start point able to tap water and now weapons they will point right here. So, 197 00:26:59.190 --> 00:27:05.100 William Cheng: When you copy pointer. They point to the same place, right, so before this picture. You know, before you get here it looks like this. Right. 198 00:27:05.400 --> 00:27:15.120 William Cheng: Start point oh point here Taekwondo point here. If you say start pointing equal to tap pointer. I'm going to copy this point to into the SharePoint or when I finish copying, they will point to the same place. 199 00:27:15.360 --> 00:27:20.010 William Cheng: Okay, so therefore, in this case, when I finished doing this, you know, they will point to the same place. 200 00:27:20.280 --> 00:27:23.910 William Cheng: And now I will continue with that right tap point or equal to stream char. 201 00:27:24.090 --> 00:27:33.570 William Cheng: Star pointer, a backslash t now star point oh point right here. So I'm going to start it stuff on this memory location and keep looking about backslash T. I'm going to end up with a pointer pointing right here. 202 00:27:33.780 --> 00:27:40.530 William Cheng: And then since tap point over here not equal to zero. I'm going to replace this with a zero and then point the pointer right here. So a number like that. 203 00:27:41.490 --> 00:27:45.000 William Cheng: Okay, so what this is all done, it will look like this. Right. So, not, not again. 204 00:27:45.330 --> 00:27:52.500 William Cheng: You know, feel to it by EOD to over here will point to start pointer and then I won't feel three over here to point right here. 205 00:27:52.740 --> 00:27:59.220 William Cheng: Right, so I can continue from here and then next time most of one over here, start pointing people to tap point to it. Right, so therefore we will point right here. 206 00:27:59.430 --> 00:28:06.120 William Cheng: PowerPoint or equal to string char, and now it's going to fail because it will not be able to find the next tab character right so we hear this case. 207 00:28:06.510 --> 00:28:15.810 William Cheng: Tab pointer is equal to stream char star point there which is here. There's no backsides T anymore because string child will find the backside zero and say, here's the end of the century. I'm gonna stop. Okay. 208 00:28:16.230 --> 00:28:24.150 William Cheng: Okay. So, therefore, what it will do is that it will return now. And now, Tom pointer over here will point you know racism, I showed this picture like this for the pointed out. 209 00:28:25.050 --> 00:28:32.670 William Cheng: There. So now when I execute a CO and tap tap point or is not equal to know and then in this case. In this case it will be air condition. 210 00:28:33.390 --> 00:28:37.650 William Cheng: Okay, so therefore, in this case, I print Erica print error message. And I quit my program. 211 00:28:38.370 --> 00:28:51.270 William Cheng: Okay. Otherwise, if I can find that one that I will continue to log in the end I want to make sure I don't have for type characters, right, because I need exactly three type characters. OK. So again, you can use your imagination and try to sort of write the rest of the code. Yeah. 212 00:28:55.830 --> 00:28:56.130 William Cheng: Alright. 213 00:28:57.870 --> 00:29:05.760 William Cheng: So this is warm up. Why so I'm sort of giving you giving you this code to walk through you to all these co, right. So, so, you know, so this will be the last time I do that. 214 00:29:06.210 --> 00:29:13.440 William Cheng: In warm up to you will be writing a lot of code on your own. So again, the lecture slides will show you how to use the P3 library to do a bunch of dressed up. Okay. 215 00:29:13.680 --> 00:29:19.500 William Cheng: But I'm going to stop, stop, sort of, you know, teaching you how to write every line of code, right. Hello, Eric. This one over here. Yeah. 216 00:29:20.040 --> 00:29:31.320 William Cheng: But, but, again, feel free to ask me a question in warm up warm up to, I'm happy to give you a lot of information about how to program, but you get into the Colonel's I'm and I'm going to start telling you what code. Right. Okay. 217 00:29:33.840 --> 00:29:41.640 William Cheng: All right, so I'll give you a lot of details of how to do things in see since the first and last assignment I will do this. You must learn see on your own. 218 00:29:41.880 --> 00:29:51.390 William Cheng: There and you need to get used to reading man pages, all those functions that I show you, you should read the main pages get familiar with them to understand exactly what those functions are doing okay. 219 00:29:51.840 --> 00:29:58.380 William Cheng: Ask question in the class, we will send email to me come to office, our, you know, especially if you're stuck. Okay. 220 00:30:00.060 --> 00:30:08.790 William Cheng: All right. There are lots of requirement in one month one look at the speck, look at the requirement that it points to look at the grading guidelines that all this kind of stuff you have questions, send them to me. 221 00:30:09.180 --> 00:30:17.220 William Cheng: And I guess by now you should get pretty familiar with the, the, the, the make file somebody just asked me a question about submitting. I'm a file. 222 00:30:17.430 --> 00:30:27.150 William Cheng: So remember, if you read the grading guidelines, very, very carefully warm up one for part A of the grading of the full four part of the grading guidelines, you will be using my make file. 223 00:30:27.480 --> 00:30:32.760 William Cheng: Okay. My name a few, as the one in the spec that will be the make file, the greater will use to grade your party. 224 00:30:33.870 --> 00:30:45.000 William Cheng: Okay, so what about party party, you need to supply their your omega. So, so your submission. You need only need to include one make file. And that's the make file that will use to great part B of the 225 00:30:45.420 --> 00:30:59.490 William Cheng: Party of the of the grading guidelines. Okay, so you don't have to submit it may fall apart because we're already have it. Okay, if you want to use your own you're not allowed to do that because we're going to get rid of it because we have to use our own version of the make file right 226 00:31:00.930 --> 00:31:03.330 William Cheng: All right, you know, so it's going to sort of briefly I 227 00:31:03.930 --> 00:31:15.420 William Cheng: Explain. You know why the original makes us satisfy the separate compilation requirement and a separate separate compilation requirement to say that if you want to construct your executable. You have to do it in three steps. 228 00:31:15.780 --> 00:31:19.950 William Cheng: Okay, first you need to comply compile one Darcy far into that file. 229 00:31:20.370 --> 00:31:30.900 William Cheng: Okay, and then you have a compiler another diversify into your data file and then you might have more step like that. And finally, you got to link all your data files together to generate one excuse to generate the executable program. 230 00:31:31.470 --> 00:31:38.010 William Cheng: Okay. So in this case, you know, for our list test. Right. What is the the executable program or executable polka is list test. 231 00:31:38.580 --> 00:31:48.270 William Cheng: Okay, so in order for you to, to, to generate a list as executable, you need to execute this command this command says link all the files together to generate the list has executable. 232 00:31:49.260 --> 00:31:53.670 William Cheng: Okay, how do you generate these two files right over here is tell you the hub. Generally, these two 233 00:31:53.970 --> 00:32:05.370 William Cheng: Hours to generate this test. Oh, you're gonna you're going to take your list test our C compiler using the minus C command line option. The minus C clamp option will compile it RC file into a data file. 234 00:32:05.730 --> 00:32:16.920 William Cheng: There. So the purpose of this slide is to generate list Estado right and then the other route. Over here, over here to say, you know what we compile your mind for to list, I see it will generate my phone to list out 235 00:32:17.280 --> 00:32:26.400 William Cheng: Okay, so using these two rules you will generate those two files. And finally, you will link them all together using the GCC command to generate the list is executable. 236 00:32:26.940 --> 00:32:33.450 William Cheng: Okay, so therefore this make file satisfy the separate compilation requirement because in the end you going to run three commands. 237 00:32:33.690 --> 00:32:45.060 William Cheng: One to compile a list has not seen to this test out. Oh, the other command will go compound my for to list. I've seen to my for to list out. Oh, and then finally going to link all of that all of us together to generate the executable program. 238 00:32:46.320 --> 00:32:56.640 William Cheng: Okay, so if you do things like this. Right. You will satisfy the separate compilation requirement. So again, really waiting on us very, very carefully, because if you don't satisfy that requirement you going to end up losing a lot of points. 239 00:32:57.600 --> 00:33:05.610 William Cheng: Right, right. So again, if you follow my recipe to start with a make file for generating generating a list as and just replace all the 240 00:33:05.850 --> 00:33:10.170 William Cheng: You know all the strings list as with warm up one you're going to end up with a valid, you know, make file. 241 00:33:10.590 --> 00:33:19.350 William Cheng: You know, for your offer for the party of the property of the grading airline. Okay, so this is assuming that you're part of the of the betting on I all your program will be sitting in a 242 00:33:20.160 --> 00:33:33.720 William Cheng: City in a file called warm up one Darcy. Okay. Some people ask me questions to say that. Can I break that into multiple Darcy file. If you start doing that, I'm going to assume that you are a programming expert. Okay. If your programming expert, then you should know what to do. 243 00:33:34.770 --> 00:33:39.900 William Cheng: Okay, if you're not a programming expert I'm sort of give you a bunch of instruction, how to actually do this in a simple way. 244 00:33:40.380 --> 00:33:44.880 William Cheng: But if you go and start doing fancy stuff while then then in that case, you, you, you're going to be on your own. 245 00:33:45.270 --> 00:33:52.800 William Cheng: Okay. Some people like to have a hierarchy of different files, put the Darcy following one directory, put it, that is fine. The other it those are pretty fancy 246 00:33:53.220 --> 00:33:57.270 William Cheng: Okay, there's no requirement to do something like that. But if you want to do this, you're welcome to do that. 247 00:33:57.720 --> 00:34:07.350 William Cheng: Okay, but again, remember that the greater has followed the grading ally. If the grading guidelines as great as the tide make warm up one if that command fails to great and we'll have to take points off. 248 00:34:08.130 --> 00:34:15.390 William Cheng: Okay, so when you get very, very fancy, you don't get to choose what the greatest going to type. Okay, the greater has to follow the grading guidelines. 249 00:34:15.930 --> 00:34:27.390 William Cheng: Right. And if you tell the waiter say please use the ID to compile my file. Well, the greatest not allowed to do that. Okay, so make sure no matter how fancy, you get in the end the greatest you'll have to follow the grading guidelines. Yeah. All right. 250 00:34:30.300 --> 00:34:36.240 William Cheng: What else over here. Good main program. Hello. Okay, I'm gonna sort of skip all that GDP should be familiar with GDP right now. 251 00:34:36.450 --> 00:34:44.970 William Cheng: And then know this is from the class website if you scroll all the way to the bottom costs website is sort of show you some of the example of the commonly use UNIX command. 252 00:34:45.510 --> 00:34:51.510 William Cheng: So you need to try these things out. If you're not familiar with Unix. Okay, so get everything happening is that a terminal right 253 00:34:51.780 --> 00:34:59.790 William Cheng: LLS list the content of the current working directory. What is the current working directory is wherever you are inside your file system. Okay. You can change your current working 254 00:35:00.570 --> 00:35:05.340 William Cheng: Directory but LS will list the current other the content of the current working directory. Yeah. 255 00:35:05.790 --> 00:35:12.930 William Cheng: All right, cat, you know, cat again do you respond standard input and then print it to standard output we saw the source code for that. 256 00:35:13.530 --> 00:35:22.440 William Cheng: More will list the content of a file. If you give it a text file, it will be more meaningful. If you give it a binary file, it will actually try to do something with it. But in that case, you know, 257 00:35:23.160 --> 00:35:31.410 William Cheng: In that case it might not do what you expected to do. Okay, so therefore they make more sense for them for us to use more to look at your source code look at your make file. 258 00:35:31.800 --> 00:35:38.580 William Cheng: But don't don't use the more command to look at executable file. That means you should try it to get a feel of what it looks like when you look at binary file. 259 00:35:39.390 --> 00:35:46.920 William Cheng: That PWD look at the current working directory to show you where you are inside your fastest them and that will be your current I will be your current, current working directory 260 00:35:47.610 --> 00:35:48.660 William Cheng: Make there is that you 261 00:35:48.990 --> 00:35:58.380 William Cheng: Followed by a directory name is that you can actually create a subdirectory your current working directory. So if you say, Mater. A warm up one you're going to create a sub directory called warm up one right and then if you 262 00:35:58.620 --> 00:36:05.820 William Cheng: You can actually change directory into it using the CD command. So you can say CD directory name and you will change directory into that directory 263 00:36:06.270 --> 00:36:15.360 William Cheng: Okay, if you just type cd what it will do is it will take you back to your home. Okay, there's a directory that's know as your home directory. So if you type cd it will take you back to your home. 264 00:36:16.230 --> 00:36:23.280 William Cheng: Okay, so you can actually go Ed type cd you'll be at your home directory and you type PWD it will show you where your home directory is 265 00:36:23.850 --> 00:36:30.240 William Cheng: Where they can do out there to see what kind of directory are inside your home directory. So this way you can try to learn about your environment. 266 00:36:30.870 --> 00:36:40.980 William Cheng: OK. So again, if you want to, you know, start doing programming. You need to know what kind of environment you're in. And so by playing around with all these UNIX command you get familiar with your environment. Okay. Very, very important to to learn how to do that. 267 00:36:41.730 --> 00:36:51.660 William Cheng: Well, the next one is the command to copy files. So you can say copy, you know, you basically say CP x and y. So, this one will copy x into why 268 00:36:52.170 --> 00:37:01.770 William Cheng: Okay, if y already exists, you're going to get a and then you're going to get. You're gonna get a, get a question to say are you sure you want to do that, you know, something like that. So again, you answer yes or no. Okay. 269 00:37:02.460 --> 00:37:07.680 William Cheng: Move you can move a file from x to y. Right. So in this case, why already exists. Going to get an error message. 270 00:37:08.190 --> 00:37:12.450 William Cheng: The why of your can also be a directory so you can move a file into a directory. Yeah. 271 00:37:13.020 --> 00:37:23.130 William Cheng: You can look us the men command, followed by command name right, so, so, so, by the way, every time when you run a UNIX command. The first part of the command line is typically the name of a program 272 00:37:23.520 --> 00:37:32.130 William Cheng: Okay so LS is the program cat is the program is more progress. I think more is also program PWD. I don't think that's a program. Maybe it's a program 273 00:37:32.460 --> 00:37:38.190 William Cheng: Okay. So anyways, the first part of your command line over here is either a program or as part of your show. 274 00:37:38.580 --> 00:37:46.980 William Cheng: You guys will go. What does this show shows your command shell command show is the one that interpret what you're typing and trying to decide what to do. And if you type of program what he would do is that they will call for 275 00:37:47.280 --> 00:37:51.240 William Cheng: You know, make a copy of itself and then it will make the exact system called the radio program. 276 00:37:52.140 --> 00:38:02.250 William Cheng: Okay, so. So again, we're using a terminal where you are, what what what's been run over here is a command shell to command shell is typically it's a bash if you use batch or TC show if you use TC show 277 00:38:02.790 --> 00:38:08.310 William Cheng: OK, so those are your command shell. So again to get familiar with that. All right. You can also remove a file. 278 00:38:09.060 --> 00:38:16.770 William Cheng: So you can remove the followed by a file. And you can also remove a directory, followed by empty directory name because the directory is not empty. 279 00:38:17.340 --> 00:38:22.440 William Cheng: Removed directory is going to fail because you can get error message to say that you cannot remove a non empty directory 280 00:38:23.250 --> 00:38:31.590 William Cheng: That this command called PS. It's called process status, it will show you all the processes that you that you're running 281 00:38:31.980 --> 00:38:35.550 William Cheng: Okay. Well, it's actually when I show you all of them, it will show you some of them. 282 00:38:36.090 --> 00:38:43.770 William Cheng: So if you type PS, it will show you a few of the processes that are running. So again, you should try this command. Look at the printer and try to understand what's going out there. 283 00:38:44.400 --> 00:39:03.720 William Cheng: You want to see everything because they've PS a you x w i think that's coming on algebra here. AMIENS join me everything, all you meaning that show me only user processes X the X says extended format you try to print you a lot of sorry 284 00:39:05.370 --> 00:39:11.100 William Cheng: I don't know what else does, you know, a W over here show you the long format or the wife format to show you a lot of information. 285 00:39:11.340 --> 00:39:17.040 William Cheng: OK. So again, you can omit some of these you know the the RD these characters over here to see they actually show you a different outcome and 286 00:39:17.280 --> 00:39:22.260 William Cheng: Also, you can look at the man pages for PST would tell you all the command on option. And there are lots commanded options. 287 00:39:22.830 --> 00:39:33.870 William Cheng: Okay, so again you know when you're running on the Ubuntu Linux system. If you want to know what kind of program that you're running in that case good run PS. Yeah, there's another command called P S tree. 288 00:39:34.710 --> 00:39:45.870 William Cheng: Okay, what it would do is that I will show you the printout of a PS commit, but in a tree data structure. Okay, so therefore you actually know inside your Linux operating system, who is the you know the 289 00:39:47.190 --> 00:39:52.800 William Cheng: Because, because for Unix and Linux system every process is required to have a parent process. 290 00:39:53.970 --> 00:40:01.590 William Cheng: Okay, so therefore you want to see the entire parent child relationship inside this tree hierarchy. You can use a PS tree, you know, command to look at the entire 291 00:40:01.890 --> 00:40:10.680 William Cheng: You know hierarchy. And then you will see that at the root of the hierarchy, there's gonna there's going to be a special process. Right. That's a special process because that process does not have a parent. 292 00:40:12.060 --> 00:40:17.760 William Cheng: Okay, so there's only one process that especially that doesn't have a parent all the other processes. They must have a parent. Okay. 293 00:40:18.540 --> 00:40:28.110 William Cheng: Right. So when you type the PS command. The first thing that it will show you. It's called the process ID, right. We'll talk about the process of identifying right it's just the integer. It's a 16 bit number 294 00:40:28.470 --> 00:40:35.700 William Cheng: So you can actually kill the program by saying, kill, followed by the process ID. Okay, so this way you will kill the program. Alright, so we're going to be very careful. 295 00:40:36.120 --> 00:40:43.140 William Cheng: If you try if you end up killing your own terminal, then in that case your terminal will disappear. Okay, so again, I'll be very careful. The command. 296 00:40:43.980 --> 00:40:49.110 William Cheng: Other commands over here like Pico pico is how you edit the file, right. So again, this is a very, very user friendly. 297 00:40:49.650 --> 00:41:01.410 William Cheng: You know, a command line editor, so you can run Pico followed by you know you'll make file or your car or something like that and see what it does, guys, again, read the screen. The screen will tell you all the commands that you allowed to use inside Pico so 298 00:41:01.920 --> 00:41:07.860 William Cheng: So if you don't know any command line editor pico is actually go on to us. Okay. Because it's very, very simple. 299 00:41:08.160 --> 00:41:17.430 William Cheng: And you know all the commands are on the screen. Then finally, when you're done, you can type exit when you type exit. He will quit your login you will quit your luggage. I will cut you a quick commercial 300 00:41:18.660 --> 00:41:29.940 William Cheng: Alright. So again, if you're not familiar with these commands, I strongly recommend you to play with them now because later on, things will get a lot busier you don't have time to learn Unix anymore. OK, so now it would be a good time to do it. Yeah. 301 00:41:32.010 --> 00:41:36.960 William Cheng: Alright, so I'm going to sort of briefly talk about warm up to right because so far in 302 00:41:37.380 --> 00:41:46.140 William Cheng: We have weapons to three lectures at the end of lecture three I show you one piece thread function is called Peter create. So now we know how to create threats. 303 00:41:46.590 --> 00:41:54.210 William Cheng: Okay, but we don't know what to do, what to do about anything else. Okay. So, therefore, we can't really talk about too much, right. So, so what I want you to do over here is that 304 00:41:54.540 --> 00:42:01.890 William Cheng: You could done with warm up one. Maybe you should look ahead in the lecture slides to look at some other piece of functions are and you will see that there's really not too many of them. 305 00:42:02.850 --> 00:42:11.160 William Cheng: Okay. So, so what we should do is that we should learn as few function as possible and try to learn these functions very, very well. And don't get too fancy. 306 00:42:11.850 --> 00:42:18.660 William Cheng: Okay, some people start reading the internet, you know, read the entire P through a book, I will try to learn everything about pizza and we can do that. 307 00:42:19.050 --> 00:42:24.930 William Cheng: Okay, but in the end you try to own, you know, what's important is to understand what every one of these function does. 308 00:42:25.380 --> 00:42:33.060 William Cheng: Okay, so if you only have a small set of function, you need to learn. Then there's a better chance that you understand them thoroughly. If you try to learn 20 you know 50 different functions. 309 00:42:33.570 --> 00:42:40.680 William Cheng: Chances are, you know, you will not be able to understand all of them thoroughly. Okay, so it's very, very important to learn a small set of function and learn them very well. 310 00:42:41.520 --> 00:42:51.720 William Cheng: Okay, so that's how we're going to do in chapter two, we're going to teach you a small set of Peter functions need to learn, you try to understand them perfectly. Yeah. Alright. 311 00:42:52.950 --> 00:43:01.200 William Cheng: So warm up to is a multi threading exercise, right, especially if you haven't, haven't done any multi threading code. This will be very, very challenging. 312 00:43:01.620 --> 00:43:04.710 William Cheng: Okay, so, so you need to start this as early as possible. Okay. 313 00:43:05.400 --> 00:43:17.430 William Cheng: So when we need to do is that when you learn so so so multi threading. We know we already see how to create a threat right so then when you do data is that, you know, when you create a threat. So right now we only know how to create a threat. How do you actually wait for a threat to die. 314 00:43:18.540 --> 00:43:23.220 William Cheng: That we know that for for processes, you can make the way system called the way for child processes guy. 315 00:43:23.640 --> 00:43:29.310 William Cheng: But what about for threats. Right. Some people will guess what, maybe there's a function called peace throw away. As it turns out, there's no such function. 316 00:43:29.850 --> 00:43:39.840 William Cheng: Okay, so you know next section, we're going to sort of show you some other functions and the function. I usually use after you create a create a threat, you need to wait for a threat to die. And then, you know, that kind of stuff there. 317 00:43:40.380 --> 00:43:50.760 William Cheng: Alright, so, so, so, so here we we we need to learn, you know, of course you can also, you know, look. Look at this book. You're not required to buy this book. 318 00:43:51.060 --> 00:43:58.290 William Cheng: Any kind of introduction to P3 that you can find on the internet that they're all just fine always just start reading the the lecture slides. 319 00:43:58.950 --> 00:44:06.030 William Cheng: Okay, so let's I will give you a preview what I'm going to talk about. So again read them very, very carefully and try to try to look at the main page and try to understand them. Yeah. 320 00:44:06.540 --> 00:44:15.150 William Cheng: Alright, so one thing that you need to learn is how to create threads. How to wait for them to die, you know, this kind of stuff. And then the other part that you need to do is to learn how to how you know 321 00:44:16.530 --> 00:44:19.320 William Cheng: I mentioned before how to perform concurrency control. 322 00:44:20.790 --> 00:44:30.720 William Cheng: Okay, so in this class to do to perform concurrency control. You only have to learn two things. Okay. One of them is called new tax and the other one's called condition variables. 323 00:44:31.530 --> 00:44:38.280 William Cheng: That the P3 library, give you a lot of other stuff. I'm going to ask you to resist temptation to learn all the other stuff. 324 00:44:39.360 --> 00:44:49.590 William Cheng: Okay. As it turns out, by only using new tax and condition variable, you can actually use them to do every kind of how possible concurrency control. You don't need anything else. 325 00:44:50.100 --> 00:45:00.090 William Cheng: Okay, by using new types of them is variable that's sufficient to implement all the other P threads, you know, primitives. Okay, so therefore we should focus on how to use me to x and how to use condition variables. 326 00:45:00.570 --> 00:45:10.830 William Cheng: There. Here are some of the functions that you need to get familiar with new tax law contacts unlock condition way condition signal condition broadcast and that's all you have to learn about the the these functions. 327 00:45:11.970 --> 00:45:17.790 William Cheng: Okay. So, don't you know there's, again, you know, yeah, if you go to, you know, the internet, you're going to search all the other functions. 328 00:45:18.060 --> 00:45:27.360 William Cheng: Try not to use the other functions or I tried to learn how to, you know, try to learn how how to use exactly these five function calls for you to synchronize the threats are so 329 00:45:28.020 --> 00:45:35.790 William Cheng: What does it mean synchronizes threat right so synchronize the stress that means that you need to apply concurrency control so that these three, I will not step on each other's toes. 330 00:45:36.630 --> 00:45:50.400 William Cheng: Or so in the next lecture, we're gonna start talking about concurrency control now. All right. The other stop, I'm going to leave the other stuff to talk about in the next, you know, in the next discussion section. Okay. Alright, so I'm going to give you a 331 00:45:51.990 --> 00:45:58.440 William Cheng: quick preview of what the one more possible. So look like so warm up why you're supposed to get. It's a multi threading exercise. 332 00:45:58.860 --> 00:46:02.970 William Cheng: Some people, you know, get to see the military exercises new tax or condition variable. 333 00:46:03.630 --> 00:46:11.220 William Cheng: We're going to make your life very, very simple and asked you to only use one new tax and one condition bearable. Right. So again, right now, you don't know what they are. So, so again, 334 00:46:11.820 --> 00:46:25.260 William Cheng: Don't worry about them too much right but but but but you know what do you understand is that this is not a new test and conditioning variable exercise. Okay. Because if I wanted give you a new tax or conditional variable exercise. I'm going to give you an exercise that has 100 new tax. 335 00:46:26.280 --> 00:46:33.570 William Cheng: Okay, that sounds very, very scary and your code is going to be very messy. So over here, I'm telling you, I'm going to make your life simple by using only one new tax. 336 00:46:33.870 --> 00:46:45.180 William Cheng: Yeah, so the purpose of this program is is to create multiple threads and have multiple threads synchronize with with each other using one new tax and using one condition variables. Okay, that's it. 337 00:46:45.960 --> 00:46:50.670 William Cheng: Okay. So in this case, what are your, what are the things that you need to work together. 338 00:46:51.120 --> 00:46:59.910 William Cheng: So this picture sort of summarize what are the threats. Right. So there could be four different threads. One is called the packet arrival through so so basically over here. It's called a token bucket filter. 339 00:47:00.720 --> 00:47:11.040 William Cheng: So internet actually use this to control the traffic that goes into the internet, that's going to be going through the internet. So for example on the right hand side over here is going to be the internet I net over here on the right hand side. 340 00:47:11.790 --> 00:47:22.620 William Cheng: There on the left hand side over here is your machine your machine is trying to generate Pakistan into the internet. So what I can, I can do that. I can actually use the token bucket filter to control the traffic that goes into the Internet. 341 00:47:23.820 --> 00:47:33.780 William Cheng: Okay, so the packet over here going to generate a lot. All kinds of crazy pattern over here when when it goes to a token bucket filter when it goes into the internet to in that case the packet, going to the Internet will look nice. 342 00:47:34.770 --> 00:47:43.680 William Cheng: Okay, so when you are running a home where you're using your, you know, I guess if you are watching movie at home or something like that, you're surfing the internet over here. 343 00:47:44.190 --> 00:47:48.810 William Cheng: The traffic that goes into the internet needs to be nice and smooth. Okay, so therefore typical to happen is that 344 00:47:49.260 --> 00:47:55.830 William Cheng: Your internet service provider will install a token bucket filter. So this way you know your data that go to the internet is not going to be to agree. 345 00:47:56.310 --> 00:47:59.220 William Cheng: OK. So again, this is not an African class. We're not going to talk too much about it. 346 00:47:59.850 --> 00:48:09.600 William Cheng: So in order for us to simulate the operation of the token bucket filter. We're going to end up creating for threats, right, one of the threads over here is going to create a packet that goes to the top of buchalter 347 00:48:09.840 --> 00:48:17.220 William Cheng: Okay, another thread over here. That would be the one that creates the tokens. Okay, so this one is called a token threat and the other one is called the package. Right. 348 00:48:17.850 --> 00:48:27.630 William Cheng: Now and then we're going to use to server threat over here, the server threat over here is the one that's going to actually send packet into the internet. Okay, so these are called server thread going to be server through as one is over there so 349 00:48:28.620 --> 00:48:35.460 William Cheng: Yeah. So your job is to create these four threads and have all these four threads work with each other. 350 00:48:36.420 --> 00:48:44.040 William Cheng: Okay, so how do you have them to work with each other. So that's where you will access all about you try to sell. So the idea here is that we're going to run for threats, right, if you're, you know, 351 00:48:45.330 --> 00:48:50.670 William Cheng: If your machine has you know 10 different CPU. It is possible. All these four threads will run in parallel. 352 00:48:52.080 --> 00:48:59.460 William Cheng: Programming reality there's there's actually the fifth threat right the filter is going to be your main threat. So you're going to start with your main threat right you start executing. You say your main function. 353 00:48:59.670 --> 00:49:11.280 William Cheng: Inside your main function over here. You're going to create these four threads. Okay, you're gonna create the package thread the tokens, where the servers are number one in the server third number two. And now you told us what that does that. Go ahead and do the right things. 354 00:49:12.300 --> 00:49:19.740 William Cheng: Okay, so therefore you need to write code for these four threads right we'll talk about in the previous lecture. These first procedure, you're going to write the first procedure for all these threats. 355 00:49:19.950 --> 00:49:27.090 William Cheng: And then when they execute the code is that the first procedure that we're going to end up, you know, working together. So the package threat over here. 356 00:49:27.420 --> 00:49:38.310 William Cheng: Is going to be the weather generate packet. So what I packets right packet is the same thing as your warm up wine you have been transactions. So again, these are objects you create them and what you would do is that you will add them into Q1. 357 00:49:39.030 --> 00:49:46.200 William Cheng: Okay so Q1 is my forward to this. Okay, so basically what you do is that you call a pen on this one over here at this packet of Q1 and then 358 00:49:46.470 --> 00:49:53.760 William Cheng: You know, the, the packet at the head of the cube over here. In order for this package to go to q to it needs to wait for enough tokens. 359 00:49:54.180 --> 00:49:56.730 William Cheng: Okay so initially this token button over here is going to be empty. 360 00:49:56.970 --> 00:50:08.970 William Cheng: The job of the token threat is to add tokens into this token bucket over here. So, one is that as you add more tokens into the swear every time we add a token into the talking about a you will check if the first packet over here has enough token. 361 00:50:09.510 --> 00:50:14.280 William Cheng: Okay, if that packet has enough token, what you will do is that you remove that packet from Q1. 362 00:50:14.580 --> 00:50:27.660 William Cheng: How do you run a packet right my for to listen link and then you add this packet to cue to over here also you know because this particular part of the package required. Okay. You will also reduce the number of token in the top of bucket. 363 00:50:28.080 --> 00:50:38.610 William Cheng: To match the requirement of the requirement this packet. OK, so now this packet will go into Q to I want to get into Q2, then what you need to do is that you need to wait for the server to become available. 364 00:50:39.090 --> 00:50:48.570 William Cheng: Okay, if it turns out one of the server of yours available over here, then you are there, you need to wake up the server. Okay, so in this exercise, we also need to learn how to wake up a sleeping threat. 365 00:50:49.860 --> 00:50:57.570 William Cheng: Okay, so why, why are these were sleeping well because they don't have any package to transmit right so if they don't have any package to transmit, then they should be sleeping. 366 00:50:58.260 --> 00:51:09.690 William Cheng: Let's again. Let's start from the beginning. Again, you start with your main threat you create all these four threads. Okay, so what is that one of the server festivals be doing well at the beginning. They have no package to transmit so they will all fall asleep. 367 00:51:11.220 --> 00:51:19.260 William Cheng: Okay, so that's very important to understand in the beginning, over here, they will fall asleep so so in the lecture window where they're going to fall asleep right they're all going to fall asleep in a predictable place. 368 00:51:19.650 --> 00:51:25.800 William Cheng: So this way you know when the token throughout over here, move apart from Q1, or Q2, they will be able to wake up one of these threats. 369 00:51:26.160 --> 00:51:39.720 William Cheng: OK, so maybe one thing that you would do is a wake up call them. Or maybe you will you will. One of them if you wake up all that you got to make sure that only one of them will be able to read remove a packet from q2 over here and start transferring again. 370 00:51:40.860 --> 00:51:51.450 William Cheng: Okay, if you only wake up one of them, one, of course, only one of these three I will pick up a package from Q2 and this are transmitted again if you wake up both of them only one of them should remove a packet on cue to what the other ones gonna go back to sleep. 371 00:51:52.680 --> 00:52:02.160 William Cheng: That one of q2 over here has five packet wasn't in that case, you know, when you wake up both of them. One of them will pick up the first packet and then he will remove from Q2. And then the second one will remove the next packet 372 00:52:03.780 --> 00:52:13.440 William Cheng: Alright so what you want to do that. You want to make sure that you write the you know the code that you write for all these threads, no matter what is the condition in Q1 and Q2, they will all they will always do the right things. 373 00:52:13.890 --> 00:52:16.530 William Cheng: Okay, so by learning how to use all these pieces function in 374 00:52:16.920 --> 00:52:21.360 William Cheng: India, you will be able to implement this pretty good so I called the sort of a simulation. Right. 375 00:52:21.510 --> 00:52:29.700 William Cheng: You're going to simulate packet arrival over here you can simulate token arrival and he also going to simulate package transmission. So in this case, where you're transmitting a packet, you also go to sleep. 376 00:52:30.540 --> 00:52:37.140 William Cheng: Okay. So you saw. So if this packet transmission take off 10 seconds over here. So what you will do that. You're going to have your threat sleep or 10 second 377 00:52:37.320 --> 00:52:45.300 William Cheng: After 10 second you gotta, you gotta declare that hate the packet has been transmitted. So what it will do is that you will get you will try to go to q to to see if there's any more work for you to do. 378 00:52:46.740 --> 00:52:52.440 William Cheng: Okay, so yeah right now. Maybe it doesn't make any sense anymore and that's perfectly okay right in the next lecture I'm going to sort of teach you 379 00:52:52.710 --> 00:52:58.560 William Cheng: All these pieces function you going to put them all together and then you're gonna write all these four threads and you're going to make sure that they work together. 380 00:52:59.640 --> 00:53:08.130 William Cheng: Whereas, again, the way they work together is that even if you have many, many CPU, they will all be running, running simultaneously, they will always perform the correct operation. 381 00:53:08.640 --> 00:53:17.190 William Cheng: What if you only have one CPU why if you only have one CPU. The only one threat can be running at a time. So again, you know, you will still perform the correct simulation. 382 00:53:19.080 --> 00:53:21.810 William Cheng: Alright, so, so I'm going to sort of end the lecture, you know, 383 00:53:23.520 --> 00:53:28.230 William Cheng: Right now. So again, you know, all the pieces out. We're going to sort of talk about the next lecture. 384 00:53:28.770 --> 00:53:41.100 William Cheng: So if you have question for the, the, the, the foot for the TA in tomorrow's discussion a lifestyle session. Don't ask too many questions about what up to because you should ask a question after the next section. 385 00:53:41.670 --> 00:53:48.420 William Cheng: Okay. All right. I'm saying, I'm just give you a star, just in case somebody is finished with warm up one already. And they want to start working on one or two. Yeah. 386 00:53:50.220 --> 00:53:51.660 William Cheng: Alright, see you next time.