It's 2024, folks. Welcome to the new year. But wait, something's lurking from around the corner. Something that the people like Disney don't want you to see. Mickey Mouse, more specifically, the Steamboat Willie version of Mickey Mouse is now in the public domain.  Steamboat Willie with the Steamboat Willie version of Mickey Mouse was released in 1928. And now because of copyright law, after 95 years of holding a copyright over something, it then goes into the public domain, which means that Disney now does not own the rights to that version of Mickey Mouse anymore. We saw this happen a couple of years ago. The copyright for Winnie the Pooh ran out. And then we saw stuff like Pooh, Blood and Honey or whatever that movie was. People are now allowed to take that IP and make whatever they want with it without being sued. And so now that is happening with Mickey Mouse. So not only is stuff happening similar to Winnie the Pooh, there are a few horror movies being announced.  With this, they dropped it, I think, right on January 1st. Yep, right on January 1st. I actually haven't seen this. Let's watch it. First ever Mickey Mouse horror film. This is going to be so bad. This looks awful. Wait, guys. Angry Birds Coin Pusher that I'm obsessed with. The real villain in this movie, taking money from not only children, but your favorite YouTuber. God, we have to stop them. I want to go back. Yeah, he's like, completely in love with me. He's totally disgusting. He's like, Tina, Tina, I'm here. I thought at least the Blood and Honey trailer looked like kind of fun and entertaining. You never say. But this looks awful. This looks real bad. That little prop looks cool. But this looks so bad. The mouse is out.  Mickey Mouse's Mickey's mousetrap. Oh, God. OK, so the original idea for this video was I wanted to look at like public domain memes and look at the memes of Steamboat Willie. But now I have some things that I want to talk about. This to me seems just like an obvious cash grab, which all the right to them to do so.  It's like, OK, go you guys for being able to take this thing that was previously Disney IP and basically profit from Disney. But at the same time, it feels like a blatant cash grab. So this happened with Winnie the Pooh. This movie was made for $100,000, which you might think at first $100,000, that's a lot of money. That is zero dollars for making a movie and gross worldwide. It made five million. So it made an insane profit despite most people thinking, and granted, I did not see this movie. Most people think that this movie was absolute garbage. And so it looks like that same thing is happening here where they're just like, OK, the IP is up.  Let's see if it already has a... Oh, it does. What did 800K? 800? I'm not trying to rag on them because it's completely within the right, but it does set a shitty precedent. It doesn't feel like there's any like heart into it. Again, this is all just speculation from me and what I'm seeing just off of that being like, wow, that looks awful. And it looks like they're just trying to gain off of the release of the IP. I will probably not see this movie. I feel like a lot of people probably will. I will be interested to see how things play out because of two things. One, it's Disney. Two, the copyright is up for the Steamboat Willie version of Mickey Mouse, but I wonder how specific even just like this mask, like you can obviously tell that it's Mickey Mouse. What's stopping Disney from being like, no, this is not Steamboat Willie Mickey Mouse. That is Mickey Mouse, Mickey Mouse. You know what I mean?  So that'll be really interesting to see what happens with that. How do you differentiate? I have no idea.  The fact that they uploaded the whole thing with no edits is kind of awesome. Like this is fully legal. They don't have to jump through any loopholes. That's the beauty of public domain. This is why, so it's just the first, it's just Steamboat Willie in its entirety and they just uploaded it, which is completely legal.  See, it is really interesting. It's not like copyright stops people from making like memes already. Again, it'll be interesting to see what actually gets made from a show or a movie standpoint. And again, it does kind of suck. It just seems like cash grabs initially, but I really hope that at some point people use these IPs in a really fun creative way. Steamboat Willie minus one.    This is not funny. It's exactly right. Because see, it would have been cool if like, they wouldn't be able to start production, I imagine, until the copyright runs out.  If Ari Aster made a Steamboat Willie horror movie, they started production like a few years ago and then they release it. They don't even tease it. They just drop it in theaters on January 4th. God, that would have been sick. But I imagine that you can't actually start production on something. But it's not being released. So how does that work? Are there any copyright lawyers in the comments? Would you need to get the rights to Steamboat Willie or any IP before production? Or can you do production without the rights and then release it once it's public domain? For instance, with music used in movies. I'm pretty sure at least. You can make an edit with a certain song before getting the rights to it as long as you don't release it without having the rights. You know what I mean? So can you then go into production on a thing that you don't have the rights for knowing that it's going into the public domain? I don't know. Let me know in the comments. If anybody's a lawyer. First cartoon together, Steamboat itchy. Steamboat itchy. Did they get in trouble for that? This is the Simpsons. While drawing Steamboat itchy sequence, the animator's talking referred to it as Steamboat lawsuit. I just wanted to talk about. I thought it was gonna be the shot of him with a gun. Oh, interesting. Steamboat Willie went into public domain on January 1st. However, many creators are experiencing auto copyright claims by Disney for the short. Okay, so Brock Baker put out a dub of Steamboat Willie. Okay, it does say claimed by Disney. A lot of times you'll get a claim for something and it's from a different company and it's a false claim and they'll just try and claim it until you dispute it. That'll probably be happening for a while because it is an automated system. So it'll just be like, okay, we see Steamboat Willie but like Disney can be like, this is our content. Like even I can see on my end, this is my copyright where it says a content match of things that I have uploaded and then different channels. Like this is 20% of that video, 10%. This is 100% of their video is my content. Sometimes I care, sometimes I don't. Somebody uploaded a one hour version of a cover that I did. I don't really care. So Disney can see that and then they can claim a bunch of stuff but a lot of times it is an automated system as well where it'll just auto claim stuff. So I imagine that's what's happening. So it's probably just gonna take a bit for the system to adjust and be like, oh wait, we can't claim this thing anymore. But it's also Disney. So they might just try and get away with it. Steamboat Willie in the public domain. This video was way different than I expected it to be. I was gonna just look at Steamboat Willie memes but you know, we had a conversation about copyright law and my thoughts on people just making shitty horror movies right out the gate.  I don't really care but I wish that they were a little bit better in my opinion. I know what your thoughts are about Steamboat Willie going into the public domain, what you would like to see, what you don't like seeing. And if there's any, if there's any lawyers in chat, you know, leave some comments about copyright law because I don't know anything. All right, I'll see you.


So, as I said, I have no format, no slides, no nothing. This is going to be a dialogue, any question and any problem that you want me to solve or any other thing that you want to ask, you are welcome. It is an open house. So, let us start with any problem, any programming question where you have had difficulties or any concept in which you have had difficulties. How to read a CSV file?  It is a file with plain text. So, you can directly open it using g edit or you can directly read into a program using your get line function. So, if you have an array or a string, you just say get line and that entire string one line will come. So, there is no difference. If you have a problem, you should rename it as a txt file because some programs may not recognize dot CSV extension as text. So, that is not a problem at all. But I thought the file which was given, the sample file which was given was a txt file, right? So, I have not done anything. I have not converted a CSV file into this or something. I simply renamed it as dot text. So, but in that there are commas and different spaces. So, how to read as an array is given the… He is being smart. He is asking me to solve the assignment problem so that he can submit it. That is not fair because the assignment deadline is actually being extended. Today morning I had talked to some students who had come, your team leaders for the project. And I have said that while there will be no more assignments in this course, this particular assignment also is extended. All assignments you can resubmit if you want to up to the end of the coming week. So, even if you have submitted earlier some assignment which was not correct or which you wanted to improve, you can actually resubmit all those assignments over the next week. So, since this assignment technically is an individual evaluation, I would not like to specifically comment on the issues related to that assignment. But I can help you out in finding out how you can gloss over let us say spaces. It is a spaces here or spaces there or how do you detect a comma? That is a generic problem. So, since comma is part of the assignment, I will not take comma. I will say let us consider full stop any other punctuation mark. So, if I have a string how do I detect a punctuation mark? That is a problem, right? Basically it is the simpler version of that problem is given a string, how do I detect any existing punctuation mark in that array? In that string. So, I think I have this I was planning to discuss with you when the assignment time was over. I had constructed deliberately a program. Is this a correct problem statement? How to locate a particular symbol? So, let us say there is a symbol which is some character we do not know which one. And let us say there is some array called let us call it I think I had called it string is a reserve word. So, let us use some other this thing. Line is also actually reserved. I do not like it. Let us simply call it L for line. So, L whatever. Now, as you know the string arrays are null terminated. So, which means if I have a string here, let us assume this L contains. So, it contains H O W 1 blank A R E 1 blank Y O U 1 question mark 3 blanks and F I N E find full stop. This is what is there in that array. Now, how will these symbols be inside this? You know for example, that L 0 will be actually containing H L 1 will contain O small O L 2 will contain W. And just to get to the blank L 3 will contain a space. So, let us say we are interested in identifying space and locating full stop locating question mark. These are the punctuation symbols. Let us assume that for some reason we want to finally get a string which is we just contains we will call it a result string. In the worst case the result string will be as large as the input string. So, we will call this R 256 another string which I am declaring.  I want this string to be inside this R. So, what I want to do? I want to remove all the blanks, all the question mark, all the full stops and I just want to compress it into this. Is that a fair approximation of the problem that you are facing? Now you know that the way the strings are contained inside. If this is the string then actually the last element at the end of this will be a backslash N. Are you familiar with this? It is a null terminated string. So, I shall have this symbol at the end somewhere. Similarly, if this is going to be the string then this will be 0th element, 1st element, 2nd element etcetera, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th and the 13th element will be backslashing. It should be otherwise C plus plus in an array will not recognize the proper string. A string is terminated by backslash oh sorry backslash 0 null terminated string. You need not correct me. It should be backslash 0. It is actually 0 value null. Did we discuss this or not in the class? Character string in a single array or we have not discussed. The last lecture null terminated string did I mention? So, you are familiar with this. We will worry about how do we get such a string inside the cell. Now for that there is a function called gate line. You can get the entire line which you type. Ordinarily if you type something like this then the C in will simply forget this. It will just take h o w as the first string and give it to the whatever you have named as variable string variable. If you want the whole line you have to say gate line because C in is not really dealing with a complete string of so and so length. It is actually dealing with individual values that is how you input numbers separated by blank and so on. But we will say that we have got this string in L and now we want the result string in R like this. So basically how do I move all the blanks full stops in the process commas are also covered. So you can actually rewrite that thing to handle commas. First we will solve a simpler problem of locating a symbol inside the array where it is. So this program code this is not part of the larger problem. This is just a sample example. Now the symbol is a single card if you recall where declared symbol to be a single character value. So this is not a string by the way. This is not an array. It can hold just one character. So you must understand the difference. If I have an array and if I want it to contain string which C plus plus can understand then that must be a null terminated string. Whereas if there is a single character that single character will be just in a single code mark I can write whatever symbol. So consider I want to detect the presence of a question mark. So I will say this is a valid assignment. So question mark symbol a question mark is assigned to symbol variable. So in that location for symbol there will be a question mark. Now I have to go over this array L. So I will declare some index. Let us say I and I want to locate the position of this symbol if I find one. So I will declare another variable. Let us say pause to indicate the position of the symbol in that array. Effectively what do I have to do? Let me break my program and get some space on the right hand side. So this is my array L and the 0th element contains what? Capital H. The first element contains O. Second element contains W. Third element contains blank, etc. And which element contains question mark? 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. So 12th element contains question mark, 13th element is blank, 14th element is blank. Sorry? 11th is it. Oh that is because 0th contains H. I am sorry. So 11th contains question mark and this will be blank. So basically whatever program segment I write the value of pause should be 11 at the end if it contains. Now how do I detect this? Very simple.  And how many elements do you search for? As many as there are there in this array before backslash 0. Somewhere it will be backslash 0. We do not know what that position is because this string is unknown to us. But we know maximum value is how much? 255. Actually there are 256 elements. So 255th element is the last element in that array. So somewhere before 255 I must find this. Actually if I do not find a backslash 0, then the array does not contain the proper character string as per C plus plus. Ordinarily what I would say? I would say for I want to go for I equal to 0, 1, 2, 3, 4 like this. So naturally I want to start with I equal to 0. I want to go maximum up to what point? 255. So I would like to say I plus plus. That is my last thing. Now what should be the condition? Without even thinking we can write down this loop because my array size is 256. First element is 0. Last element is 255. And I have to go through all the elements one by one. So let us first write a simple loop like this and try to locate a symbol here. Now how will I check this? If what am I comparing any element of array L? So if L i equals symbol. See it is as simple as that. I am trying to locate a symbol question mark. If L i is equal to symbol then I have to do something and get out. If L i is not equal to symbol then I have to increment i and go back. So if L i is equal to symbol, this is the position where symbol I have found. So I will say pos is equal to I. That means I have found it here. So when I goes through 1, 0, 1, 2, 3, 4 like this, here I detect it, I put this value into pos. That is my position. But after finding out I do not want to continue the iteration.  Then I will go here and again check. This will not be question mark. In fact there is likely to be only one question mark. So I will unnecessarily go further. I do not want to go anymore. I want to stop. What is the statement to get out of any iteration? Break. So I will say break. And that is the end of this if. If the symbol is not found at the i-th position, say 0-th or first, what do I want to do? Nothing. Simply go back and check the next position. So that means I go to the next iteration. So if there is a symbol, then this iteration when I come out, pos will have the value i. However, there is also a problem. Suppose I cheat and I do not put any question mark in the string, then what will this iteration do? It will never meet the if condition because there is no question mark in the whole string. So I will go if I equal to 0, is symbol no. I equal to 1 no. 2, 3, 4. I will cross over till i becomes less than equal to 55, I will continue. When i becomes 256, what will happen? I will come out of the loop. So I will come out of this iteration for one of the two reasons. One, when I have found a symbol. Or second, when the symbol does not exist. But I have an indication. What is that indication? When I come out of the iteration, when i is equal to 256 because I would have been incremented. Remember, when will this loop normally end? When i becomes greater than 255. So if i is 256, I have not found the symbol. If i is less than 256, that means I have come out of the iteration for a reason other than this. Remember, even if the question mark is in the last position when i is equal to 255, this if statement will work out to be true. So 255 will be equal to symbol. In which case, I will not only set pos equal to i, but I would have broken out. That means the iteration does not get a chance to increment i. So therefore, even last element is question mark, the value of pos will be 255 and the value of i will also be 255. I would not have been incremented. So a simple Dumbo thing to do is, if i is equal to 256, see how no question mark. Else, see how question mark and if you want you can put it like this, just to be technically correct. I am trying to preserve space here. Is this understood? What is the logic? So there are two learnings from this. First of all, even if I have set up a loop, I cannot blindly assume that there is a question mark and I will find it. I have to still check whether I have found it or not. There is another simpler method, however, which does not depend upon the question mark, which does not depend upon the index and that is the value of pos itself. So the other alternative that I have is to set pos equal to say some negative value, minus 1. Now I know that before starting my iteration, I can now check for pos. If pos is negative, that means it is the value which I had artificially given to pos originally, but my loop has not found pos. Why? Because if this loop had found the position, it would have been one of the values 0 to 255. So that means it would have been a positive value and therefore, if pos is positive, I have found it. If pos is negative, I have not found it. Now you change the symbol to anything else. Change the symbol to space, it will locate space. Once you have the position and you can have pos 1, pos 2, pos 3, as many positions as you want, you can actually locate positions of various symbols. So this is the way you go over a single dimensional area of character string to locate any individual symbol. Now let us come to the main problem. We will go back to page 1 again here. Our original problem we said that if we have a string which is spread out like this, ordinary sentence that we will write, somebody has written three blanks here. For some reason, I want to compress all characters. So data compression, the size of the memory will reduce. Actually, nothing reduces because I have already declared array L to be 256. The array does not shrink, but only the string gets compressed. I want to compress it like this. So what would be the strategy now? Can you figure out what is the strategy? The strategy for solving this problem will be that I have, let's draw this array L horizontally. So I have H, O, W, blank, R, blank, U, blank, no, no blank, question mark. And then I have three blanks here. And then I have, let's say, fine, full stop and backslash 0. This is my string. So this is my string L. What I want in R? I want H, I want O, I want W. So that means this goes here, this goes here, this goes here. But when I notice a blank, the blank should not go into the result string. So blank doesn't go anywhere. I have to ignore blank. I have to jump over blank. Now A goes to the next position. So A goes here, R goes here, E goes here. Is that correct? Now I want to gloss over this blank. So now Y goes here and so on. So notice that this was 0th position, first position, second position, third position, fourth, fifth, sixth, seventh, eighth. But in this array I will have this as 0, 1, 2, this will be 3, 4, 5, this will be 6. So what was in the eighth position should go to sixth position? What was in the fourth position should go to third position? Likewise this is how the compression will happen. It is obvious therefore that nothing will be served if I simply copy one by one every character here blindly. So what I have to do is I have to have two different indices. Let us say one index is I for this array L and another index J for this array R. And these two will not move in the same fashion. They will never have the same value after sometime. Initially both of them will start with 0. So J is the target index, I is the source index. The source index should move from 0, 1, 2, 3, 4, 5, 6, 7, etc. up to 255. But this index should move only when some element gets inside. If no element gets inside this array, J remains wherever. So if I have 20 blanks at the beginning, I will move from 0, 1, 2, 3, 4, 19 and will become 20. But J will become 0 because I will not put anything in design. You get this logic. So let us now try to write a program segment which will transfer the array elements of L into array elements of R one at a time provided that element is not any one of question mark, full stop or black. We may want to identify the length of the string which is inside a particular thing. How do you identify the length of the string inside an array? Simple. You keep searching the array elements till you find a backslash 0. When you find a backslash 0, that position is the last position. So before that all are the characters. If the backslash 0 position is found at pause, let us say. So all that we do is if symbol is set to backslash 0, pause is the length. Is that correct? Suppose symbol backslash 0 in the array in our previous program. If symbol is backslash 0, then in this case backslash 0 will be which position you have found out? What was the position of backslash 0? I cannot count. Anybody has counted? 19. Remember you are starting with 0. The index is 19. There is a full stop. So 19 will be full stop and 20 will be this. Now this is very interesting. If 20th element is backslash 0, the length of the string is also 20 because we start with 0. So if you count the number of characters in this string, this is 0, 1, 2, 3, 4, 5 up to 19 means there are 20 symbol. So this is only one advantage of this stupid way of array counting, array indexing in C, C plus plus which starts from 0 is that when you hit the backslash 0, the value of the position is actually length of the string. So imagine now therefore that we had put symbol as backslash 0 in our symbol location thing, then pause would be the length of that. It is better to capture that separately in another variable. We will call it length L equal to pause. Assuming that we have found out the position, length L is now length of that string inside that array. What is the advantage? Now I do not have to blindly search till 255 if the total string size is 255. So in fact there is a function in C library which can determine this length automatically. If you give that function the parameter which is the string array, it will return the length. But here we have done some good agree and found out the length. Let us now I want to transfer from L to R. So how will I transfer from L to R? I have to go over the string tell. Well let us again look back at what we decided to do. This is our logic. Go back to slide 3. The first character goes to first position and 0th position first goes to first second goes to second. Third one is a blank. We have to move over it. Seventh one is a blank. We have to move over it. We copy 8, 9, 10. Eleventh is a question mark. We have to move over it. Twelfth is a blank. We have to move over it. That is how we will get a compressed. But essentially it is obvious that as far as the first string is concerned, I have to go over the entire array element by element starting from 0 up to length. So as long as the index is less than length, I have to traverse that. At length position I know it is backslash 0. So there is no point in looking at the array subsequent. Consequently the iteration that I will have to set up, the controlling iteration for this transfer will be set up in terms of the string from which I have to copy. Is this clear? What is there at length L? There is backslash 0. But when I transfer a string, the string in R should be a valid string. That means it should also have a backslash 0 at the end. Now why separately put a separate statement to assign that last position with backslash 0? When I got a ready made backslash 0 in this string, so I simply copy that last backslash 0 also. I know that I am going to gloss over things. But I am going to miss out on only blanks and question marks and so on. Since backslash 0 is readily available if I say this, then this will mean that I am going to move my index I from 0 up to and including the length. That means up to and including the backslash 0 which I actually want. I want to copy that backslash. It is your choice. You can either run the iteration up to less than this thing. And then at the end, in the final position of array R, you can actually insert a backslash 0. Or since backslash 0 is available here, I can copy it here. Now what I have to do? If I have to check L i, what? If L i is equal to comma, I do not have to copy. If L i is equal to blank, not copy. If L i is equal to question mark, not copy. That means if it is not equal to, I have to copy. So if L i not equal to question mark, how do I write R? Vertical bars. If L i not equal to blank R. No, is it R or is it and? Because if I say R, so if it is neither this it will still be true. So what was it? Full stop we wanted to skip. You will notice that it does not matter which symbol you want to skip. Any symbol you want to skip, you write here. If the i-th element of L is not any one of the wanted symbols, then you want to copy it. Where do you want to copy it? You want to copy this into some element of R. What is that element? We said that element will be J. But wait, where is J defined? Now this is cross check. You should automatically do. Your mind should automatically do. Whenever you are writing an index for any R A, J, K, Z, POS, whatever, immediately go back few lines and see whether that value is defined. For example, when I it was fresh in my mind that I am setting value of I. It is a valid value set. But when I write J, my ears should start tweaking. Did I define J? No, I have not defined it. Suppose J is minus 304, then the first element H will go into operating system memory and my program will crash. What should I do therefore? I should set J because this is the first element. Now I know J is set. But J is preferable not to use the looping structure to modify value of J, although I can. Why? Because J is not synchronously moving with I. I is moving 1, 1, 2, 3, 4, 0, 1, 2, 3, 4. J we do not know. So J is separately maintained. So I will set R J is equal to L I. You agree that I th element will now get transferred to J th element of R. Now I want to increment I, increment J also. But I is going to be incremented by my for iteration. So I will just change J if statement has ended. I have nothing else to do. If the array element is any one of these, I do not want to copy it. If I do not want to copy it, that means when I simply move I to the next value, I plus plus, I have jumped over that element. So if there is one blank, I would jump over it. Next time again I get another blank. It will catch it here. I simply put this. Once again you made me convert all to add. Please examine whether this is correct. So let us consider what this condition means in terms of some actual value. On slide 2, we had written down this is the string. What is L 0? Capital H. So let us apply this condition that we have written on L 0. L 0 is actually having a value capital H. Let us see what happens to this if condition. Is L 0 not equal to question mark? Yes. It is not equal. So this is true. Is L 0 not equal to blank? Yes. This is true. Is L 0 not equal to full stop? This is true. All three conditions are true. Therefore, this total condition is true and I will come out in here, assign this value, increase it exactly as I desire. Consider now some other element which is here. It is L 3 which is blank. So I compare this. Is L 1 not equal to question mark? True. Is L 1 not equal to question mark a blank? False. Because this is blank. Is L 3, sorry, not L 1. L 3, L 3 and is L 3 not equal to full stop? True. So this is not equal to full stop. This is not equal to question mark but this is equal to blank. That means this condition is false. This condition is true. This condition is true. Any true and false is false. Therefore, this entire complex condition is false. When I come out here, this statement will not be executed. This statement will not be executed. I will come out simply, increase I and go back.  This is the way I can compress, depress, whatever. Now you can take as home exercise in a small tweaking of this code. For example, I could have written j equal to 0 here itself. It is perfectly valid to say and then do exactly what you did. What am I doing? I know that I have to start looking at both the arrays, transferring values. But the second array index, I am going to maintain myself but I have to initialize it. So I might initialize along with the initialization of R. Observe that unless I put something about j here, j will not change automatically. The only thing that changes is the third specification of false state. And I have said I plus plus, so j will not change. But j will change because I am going to change it in my iteration. So this saves me one separate instruction of setting j equal to 0. I would like you to consider, is there any alternative to write this kind of complex thing? Well, you will have to check this. But there is a, there is another variation of if statement in C plus plus called switch. We will not discuss that switch. Try to examine what that switch does. More importantly, there is a function built into the C string library which can automatically locate if any character is a punctuation mark. Punctuation mark includes full stop comma, question mark, exclamation mark. Does it include blank? Perhaps not. Examine that. Compare it, check it whether it works. These are all tweaking. This algorithm will work guaranteed. No issue. Doesn't matter which compiler you run it on. But if you use functions, you may make your life simpler. In this particular case, you did not use a function because this comparison is simple. But if you have to write 20 lines of code to determine whether a symbol is there or not, then you might as well consider writing a small case. Let us, for example, write down if any symbol that is given to me is full stop comma, question mark, blank or any punctuation mark or blank. Let me write a function. What will happen? Instead of writing this complicated condition, which may become longer and longer if I have more symbols to move on. For example, if my problem, so this is one solution. The second point that I am mentioning is I want to check and ignore question mark, full stop, comma, blank, exclamation mark, double apostrophe, single apostrophe. Anything else that you can think of? Colon, semicolon. Anyone of them exists in the string I want to ignore and push only the remaining string. Now imagine if your program was written like that, that if statement will become long and long and long. Now suppose I decide that instead of doing this Godagri in my main program and I have to do this with many strings, I will rather write a function. That function should return a truth value, yes or no, true or false. And it should return a value, let's say true, if the character that I send it has any one of these. And if that character which I send it is not any one of these, it should return false. So I write a function, bool function. I want to return it a boolean value, true or false. And the function name let us use is, I call it special care. That means this function I am writing to determine if a character given to me is a special character or not. If it is not a special character, then I will say not special care. That means the function should return false. But if the given character is one of the special characters, then I should say true. It is a special character. That is the function I want to write. So what shall be the parameter inside? It is called care x. So I am writing a function whose parameter is a character x. And what I have to do now? I have to just check whether it is one of those characters. I can write a Hanuman ki pooch very simply if care equal, equal question mark or this time or right. If x equal, equal question mark, then I want to return true. Or if it is x equal, equal full stop, I want to return this. Or if x equal, equal comma or if x equal, equal space or x equal, equal. You see till I get thoroughly bored with life, I have to keep writing this. Or x equal, equal double quote. It is going to be fun here. Double quote will work correctly. Now or x equal, equal single quote. Is this correct? What it will do is it will take the first single quote, the second single quote and it will assume I am comparing it with null. Because this is a character. Anything enclosed in single quote is a character. Nothing enclosed in a single quote is nothing character which is null. Okay. I will leave this as homework. How do you handle this? That's why I deliberately when somebody suggested other symbols, I added a single quote also. However, let's assume we are not checking for single quote now. That is simpler. So we remove this. But there are other fellows. Who are the other fellows? Or x equal, equal colon or x equal, equal semicolon. If x is any one of these, then what I want to say? Yes. You send me a special character. What is going to be the return value? It is a truth value. So I can simply say if this is so, return what else? You have to define it. No. True and false are constants. They are like 1, 2, 3, 4, 27, 35. So C plus plus recognizes TRUE as the truth value. And it recognizes FALSE as false value. Since C plus plus inherits this bull type from C, a zero value is treated as false and any positive value is treated as plus, as true. So it is not uncommon to find some people saying return one as return zero. Because zero is treated as false. But technically you should not do that. Zero and one are integer values. So if you declare this as int and you should correctly check for an integer numeric value in your main function then it is okay. But please note that we are writing a function to tell us a decision, true or false decision. It is only proper to declare that function to return a value of the bullion type. So this is the bullion function and what I will return will be either true or false value. So true and false are not variables already. They are actually constants. They are like as I said symbol 1, 2, 3, 4 value. They are constant value. And they are known to seek plus, plus, combined. So this will compile correctly. This will also work correctly. So do you agree that this, Godagiri that I would have otherwise done in my main program is best done separately in a function called special cap. Okay. Now let us go back to our program. I have this program here. I want to rewrite this program using this call. So let me rewrite this program. This is the segment. I keep this segment in front of me and I am going to rewrite this segment. You can read this part. All that I now need to do is I will say for i equal to 0, j equal to 0, semicolon. i goes all the way up to and including length of l and i increment i plus plus. And what do I do inside this? If I am going to call which function and what is the parameter I am going to pass? Sorry. All that I am saying is please go to that function which I wrote called special cap with the value li. If li is special cap, then what will it return? It will return as true. If it is a special cap, what do I want to do? Nothing. I just want to increment i plus. But if it is not a special cap, what do I want to do? Transfer them. So if not special cap, this function special cap will return true if it is a special cap. I want to find out when that returns false. Then only I want to transfer. So if not special cap, if special cap returns false, then not special cap will be true. And I can now transfer values. As I said, that is it. Please note that your program becomes smaller. It also becomes neater. And it also becomes more understandable because anybody else reading this program will notice what you are trying to do here is you want to ignore some special character. The reader may not understand which special characters you are ignoring. But it will be immediately understood that this is a function call because there is a bracket. There is a parameter bracket closed. So this is not a standard command. So this is a function call. Now any function call can either be a standard function in C plus plus or a function written by you. Since I will any reader will recognize this is not a standard function. Therefore you will go back and see whether there is a function that you have written. And yes, in your file somewhere and remember when you do large projects this function may not even be in your file. It may be somewhere else. Just like C functions that you use, C plus plus functions that you use, you do not write them. Somebody else has written them, right? So those functions come from some other files which are called header file. In a large project such functions which you have written could also be compiled separately by this program. The point is that any reader of this program can easily see that there is a function reference being made. One character value is going back. And what is coming back is obviously a Boolean value because I am checking whether the return value is true or false. Is this understood? Or there is a problem in understanding this? Yes or no? Okay, fine. Yeah. No, this is not a loop for j. This is a loop for i. I am increasing j. Loop is not increasing j. I am increasing j. Let us again look at that array. Yes, I really wanted these kind of questions to be asked. Let's go over this. What we said is that I am setting up an organization for i equal to 0 to i equal to 255 or i equal to length. So I will increase automatically. But remember what is my purpose? My purpose is to transfer this string into j. So let me take on the seventh slide I will write the following. This is my array l. Okay. And I want to transfer from array l to array result. Within the same loop as I move from 0, 1, 2, 3, 4, I want j to move from 0, 1, 2, but I do not want this third element to go to third element here. But I want j to change. Now please note that i is changing linearly 0, 1, 2, 3, 4, 5 up to length. So therefore I can write in the loop condition for i equal to 0 or something. But if I put j also in the loop, then it will change also linearly. I do not want that. So I am changing j myself. It is not necessary to go over an array that you must write an iteration. I could write the Gholagri of seeing r1, r0 equal to this, r1 equal to this, r2 equal to this myself. Instead I have a statement which says rj equal to something. But having assigned a value I must change j. So j is changing within the loop, but not automatically. I am changing it. And how am I changing it? Whenever I move from this to this, so j will get h here for the first transfer. I will execute j plus plus. That means j will become 1 now. I am executing j plus plus. I am giving it a command. Loop is not changing it. So j will become 1. Now I get O. When i is equal to 0, i equal to 1, this 1 I will get O here. When i becomes 2 I will get W here and I will change this to 3. Now i is 3 here. Notice I will detect this is special character. This is not to be transferred here. I will change from 3 to 4. But j will remain wherever it is. Why? Because loop is not changing j. I am changing. Now when the fourth element is A, how are you? When A comes here, A will now come inside here. Why? Because I had changed to 4, but j has remained at 3. That is what I want. Sir, you can write a loop also. j equal to 0, j is less than i. What will it achieve? Why do I have to loop? Because I do not have to go back into j. A loop within a loop will execute n square times. It will be long to put a loop within a loop because it is unnecessary. Please note that in this logic when I go i equal to 0, 1, 2, 3, 4 up to this, I would have not only completely scanned this array. I have seen this entire array at that time. And at that time I have filled this array. I did not need any other loop. In fact, if I have written another loop, it will be wrong. Because whenever there is an array of i, it will start again with 0. When I have reached here and I have put this w here, then I do not need to see j equal to 0 because I have filled it here. So in fact j should never move back. So therefore I should never have an array loop within j equal to 0 to something. That is because if there is a loop, the loop can either be stand alone or it can be inside another loop. If I have written 4 i equal to 0 and I write 4 j equal to 0 under it, then that whole loop will start with j equal to 0 for every value. Do we want that or not? So therefore it is useless to write a loop for j. Actually it is wrong. What do we want to do? We want to scan this array once and while doing it, the elements are scattered. We want to keep them here. If we do not forget the work, then we have to do the whole execution only n times. We do not have to do n square times. If you want to do n square times or two-dimensional arrays, or for the first array of every element, I want to see the whole element of the other one. When there is an array of the other array, there is a whole string that is scattered. We will see where j has to be written as a loop. So let us take an example where I will require a loop within a loop. But as far as this problem is concerned, it is wrong to put the second. Because in one shot, I want to finish off everything. Is this clear? Yes. In the first case, when we were looking at the position of the question mark, if there are other way, how do you reject that because we are getting out of the loop? In the first case, I will be getting out of the loop. But in the second case, when I am transferring, I will not forget that. If I get the next error's question mark, it will also ignore that. So let us distinguish between the two programs. The very first program you are referring to, find the question mark. This was a problem which says how to locate a particular symbol in any array of character. If you want to locate multiple occurrences of that symbol in a string, you will have to simply run a loop. And for every position, you have to output that position. So you run a loop here instead of saying pos equal to i, you will have to output that pos or you have to store it in some array, some other numerical array, that first position this, second position this, third position this loop. There is no break here. But you will have to locate this position separately. You can keep saying pos equal to i every time. At the end, there will be only one pos. So if you want to identify different positions, it is a good question. I may give it in the end, sir. But you people know this question. We are applying break, so it will break the loop. No, there is no if loop. Please remember, if is not a loop, if is a single occurrence, it will just test this. And yes or no, it will do either this or that. If is not a loop. Break will break a loop. The nearest loop, the nearest loop is for. It is a good question. Break does not break anything in if. If breaks automatically when I put this, there is nothing to break. If this condition then do this, else do this. If the work is done anyway. This is a break that will break the loop. So is it necessary to apply it in this situation or we can apply it outside? You can apply anywhere. Anywhere where break comes, the for iteration, the next iteration will go. But I do not want this particular iteration to do anything else after I have located it. I do not have any work to do. What is this for iteration? I do not have any work to do. So break, if it comes anywhere in the iteration, the rest of the iteration is kept complete. This break means that if this for loop closing brush is here, then come here. That is all it means. I have written 500 statements in between so I will go there. Break means this. So let us solve two problems. One problem is finding out multiple occurrences of a particular symbol. How do I find multiple occurrences and where they are? Because multiple occurrences. Counting is simple. So how many question marks are there in a string or how many blanks are there in a string? How will I count? You said question mark, but I will take it as blank. Any symbol is okay. How do I count multiple instances of any particular symbol in a string? So we go back to our first program that we write to locate one particular symbol, one question mark we had said. We will use the same thing to find out the number of instances. Here I will declare int I is my index to go over the array and I will declare a variable called count which will count the number of instances. I will declare a symbol as a single character and I will declare an array l of 256 elements. Oh, I am sorry. Very good. So int I count symbol, l 256. I assume that array l has been read whatever, get line or some function. Now I want to find out multiple occurrences. Since to begin with I have to assume that the symbol does not occur at all. So I will initialize the symbol to blank and I will set count equal to 0 because I have not found any symbol so. Counting this is actually very simple. I will just say for I equal to 0, I less than well if the array contains a character string the last element has to be backslash null. The last element cannot be a special symbol. But if you want whatever I mean it is up to you ordinarily I would like to actually go up to the length of the string. So ordinarily you should always determine the length of the string and limit your scan to that length of the string. So that you can do but the point I am trying to make here is I really do not need much. What I need inside this is if any element of l is a symbol I should increment the count. No statement required nothing required. I am just looking at every element of the array. If that element of the array is equal to symbol count count was 0 if I have one blank it will become 1 if blank is there in 5th position it will become 1 more. If blank is 13th position it will become 1 more and so on. At the end when I come out I simply say print sorry. The array element is incrementing automatically because of the fall loop. So what you will do 0th element if it is 5th element blank you will add 1 more. Count will become 1 more. If it is 13th element blank count will become 1 more. Remember count started from 0. Now count is incrementing every time there is a blank. At the end whatever is the value of count that will say so many blanks are there. Is it okay? This is the easiest way to count all the number of blanks or any special symbol that you want. The harder problem is the positions of blanks anywhere. So individual position I will give you an array Suppose this is my string this is my L string L Suppose this is my array See this array has 0th element H 1st element O 2nd element W 3rd element blank I want this. This is 4th element 6th element 7th element 8th element 9th element 11th 12th 13th Actually a backslash 0 because it is a character string. This is my string. Now my problem is not to count blanks If I want to count blank count will become 4 This is 1st count So if I run the previous program with symbol as blank I will get count equal to 4 Now what I want to know is that blank is occurring at what positions So I want 1st position is 3 2nd position is 7 3rd position is 8 4th position is 9 If I want to count which positions blank occurs I expect only one answer I am going to get multiple answers And I do not want to just print them. Printing is very easy What can I do? Instead of saying count plus plus If I say c out count plus plus Observe that c out count plus plus will increment the count and print it also Should I say c out count plus plus or should I say c out plus plus count or c out I c out I is the position So if I just want to indicate print the position then I can say c out I I will get the position printed But that position will be on the paper Suppose in my program later on I want to do something with these positions I want to start in this position or do something else from this position I want these positions stored If there are multiple positions I cannot store them in a single variable Either I will have multiple variables So the question is that if I want to locate multiple positions of the blank then I cannot just print them I have to put them somewhere And I cannot put them in variables How many variables will I write I do not know there are 5 positions 10 positions 20 It depends on how many it applies into an array So this time I will declare pause as an array And then keep putting a value in pause which is actually the position there How do I know how many positions are there that means how many blanks are there So I will have a simple variable which will count the number of blanks And the value of that is the maximum number of exact values assembled in the array So consequently if I have an array pause In this particular example pause 0 will contain this pause 1 will contain this 2 will contain this 3 will contain this And the total number of entries into this array are 4 So I will say number of blanks n blank should be equal to 4 at the end or blank count whatever variable Now my job is given this string l I have to scan l and assemble these positions into this array called pause So consequently my data structure will slightly change I will have of course int i where i is the what should I say index variable for scanning l I will have n blank which is my count for number of blanks in the array pause I will have pause which is also an array of integer because I am going to put positions inside it How many elements should pause have as many as there are blanks How many blanks can be there Well it depends upon who gives me input Ordinarily I am going to run this program to read character strings So I I will expect 10, 15, 20 blanks But suppose there is a sadist who actually gives you a blank line only 255 blanks Do it That is the worst case So for the worst case we make it 255 I don't need 256 by the way I don't need 256 because there is no backslash 0 this is not a character string array this is an integer array I am going to locate positions here So I n blank pause 255 my character as usual will be l 256 Since the element inside pause will have to be indexed by some other thing than i i is I am going to attach i to l You associate with one array, one index It doesn't matter if you have multiple names That way there will be never any confusion So instead of reusing index i for this array, that array whatever, whatever, there is no harm So you can declare this to be int i l That means o l array case as such For this I could have used j But remember we used j some time ago to go over another character string So let me use here another integer variable called k pause So k is an index variable which will vary over the array pause So this is a pause This I am calling k pause My own symbol You agree that it is easier to associate an index with an array if the name is similar I will never make a mistake I will never say l k pause p k pause in this search I can of course use it anywhere But I am saying that I will use it inside this Now I have to determine the positions and put them here You will agree that the basic loop structure will be same I will have to say for now what I am saying if now I have to do something more If I have found a symbol as ith position So I have to put this value of i into this place Remember in this array this statement would have been true only when i is not 0, 1, 2 but when i is equal to 3 And I want to capture 3 and put it in the first position of this array But what is the first position Later on I will have to put this 7 into second position which is 1 So that means I will have to maintain k pause independently as a separate variable So it is only proper that I start with k pause equal to 0 somewhere before my iteration begins k pause here initialize 0 Now if I find a symbol what do I have to do I have to say k pause plus plus You know I have to actually capture i So what should I say pause k pause equal to i This is the position i which is 3 I have captured 0 in this array And after doing this I will say k pause plus plus So I have put k pause 0 And after doing this I have not come here My k pause is 1 Now after this I simply say End of my if End of my for I will be equal to 4 Is it blank? No Again When i is equal to 6 Li is equal to e It is not blank So I will keep moving up and up When I become 7 I get trapped into this f Because l7 is blank When l7 is blank I will say pause k pause equal to i Remember k pause is 1 So first element not 0th element In the first element the value of i will go to 7 And after that k pause will increase to 2 You will agree I have captured all the positions of blank in this array And what would have been my k pause at that point Because k pause is incremented Every time I will have found a blank So I would have When I insert in the third element The value 9 The value will go correctly in the third element But k pause will become 4 So as a result When I come out of this iteration Whatever is the value of k pause Is the number of blanks I have So consequently Will it not be right for me to say n blank Is equal to k pause How many blanks I have discovered As many is the value of k pause Because k pause would have been 4 Observe that Another sadist gives me an array Which has no blank Don't know I will not find any blank That means if there is no entry But if there is no entry So if k pause is 0 Well this whole iteration Will be a futile exercise Of moving around in loops And coming with nothing But my k pause will be 0 So that 0 value will be assigned to n blank So how many blanks you have n blank n blank 0 So count the number of blanks So count the number of blanks And indicate the position Separately Now we will come back to that question Comma separated Fields Consider Now A string Which has comma separated values So do you remember What was the string There was a serial number Let's say 123 Then there was a comma Then I think there was roll number So let us take something Roll number So let us take some sample roll number 0 7 D 4 1 0 0 3 Then there was a comma Then there was a name Let me write my name Actually I was a student in 1963 69 So let me write 69 Modern roll number So 69 D4 I have After that what is the Lab batch, right So let's say lab batch 1 D Whatever it is And then marks, how many marks do you think I will make I will at least get 30 marks No, no, 45 is difficult I make lot many errors as you have seen My lab TA will Cut minus marks For every syntax error I make And I will get practically not more than 30 But that's okay, it's a sample What I am making is You want to separate out this field This field This field And this field, right So important thing is You want to determine commas in this string And you want to take out From 0 to first comma Then this comma plus 1 to next comma Then that comma position Plus 1 to next comma Then that comma position to Plus 1 to next comma And last field comma position plus 1 to End of the string You want to take this field Out, put it in some string This field out, put it in something else This field out, put it in something else You want to take substrings out of this string And put them somewhere else Now you can see how that POS array concept will help All that I do Is that In this program Instead of symbol being blank I put symbol equal to comma If I put symbol equal to comma Wherever the comma is The position will come in Now I want to print I will show an example because Going any further in this direction Is solving the assignment problem for you But instead What I will do is I want to find out The Name in this string Which is known to be In the third field First, second, third field Assume that this string is In L So L Is equal to this entire thing I have extracted this Assume that I have Found out the position Of all commas here POS array Can you tell me What will be the positions What will be the positions The first comma 0 is It will be 0, 1, 2, 3 Second comma is 4, 5, 6, 7, 8 No, sorry 0, 1, 2 0, 1, 2, 3 4, 5, 6, 7, 8, 9, 10, 11, 12 It will be No, sorry 12 In the next position 13, 14, 15, 16, 17, 18 19 Oh, space sorry 19 is not common here 19, 20, 21, 22, 23, 24, 25, 26 Equal Whatever, approximately equal So here 26 The next element Third element will be 27, 28, 29 And there is no fourth element Backslash 0 I have collected this I have collected it from the last program Now I have to print the name So I will go to the end of that program If I just say C out What should I print I am printing a character What is the value of I What should be the value of I From here From here From here What is this value Now 13 This is 13 And what is this value Instead of saying in absolute terms Because this will vary depending upon Someone's roll number has arrived Someone's serial number has arrived So we do not know what will be the exact position Always it will not be 13 Suppose somebody's roll number is wrongly written as 3 digit Then this will be different Suppose somewhere I have not printed this Then this will not be exact See this is the point In a data entry operation Anybody can chew up anything So you cannot guarantee that every name Will start from here Ordinarily it should Ordinarily every name should start from here But in my time I did not have the roll number of 8 digit Actually my roll number was 1742 That is all Now if I give you the roll number Your counting will be saved So you cannot make assumptions About data One thing is guaranteed The field has been separated from the comma That is the CSV file So therefore what I should do Is I should depend upon the values inside here Now what it means is I want to run a loop for I equal to something To I less than something I plus plus I just want to print this I want to print 13 characters 14th, 15th, 16th, 17th, 18th 25th, I do not want to print 26th And I do not want to print before 12th So my starting point is what will happen Pause 1 plus 1 This is 12 in Pause 1 This is my third field My first field is It runs from 0 to Pause 0 Pause 0 minus 1 Second field is Pause 0 plus 1 Pause 1 minus 1 My third field is Pause 1 plus 1 Pause 2 minus 1 So I is equal to Let me write this Pause 1 Pause 1 plus 1 I should be less than Less than If I do equal to It is not common in my name So do not print So many characters came Do not print any other name with me Do not print with me Because there will be one more index So print everyone's name You will not be able to read So after this See out Less less End L After this loop Do you now see how you can extract things Remember if I can print out certain characters In an array like this Then instead of saying see out I can also say assign this to some other Array But you have to remember to manage the index of that Array independently Anyway I think for today we have discussed Some of these things we should have clarified How do you handle elements inside character The trick is in setting up iterations Ordinary numerical computational Iterations are straight forward One to end And inside it again one to end N or N square I say iteration open Arrays when we consider string arrays Then two string arrays can be Or in one string array Asynchronously move an index Move an index Always remember You will generally not require nested iterations You will scan only one iteration If you scan it, you can get a symbol Or get a position Store it And if you want to move from there From wherever you want to move from Hold that position You can move it, print it, anything So a handling array As string elements Which contain characters Is not really difficult It is agonizing Because whatever iteration we have seen so far Those were all numerical indexes Numerical values There was no question of looking at the position of the character So there can be confusion in the beginning But what happens Many times I have seen Many of you will lose confidence Because the confusion This is going separately Like you said Why don't I do iteration Because in the problem of numerical analysis We have seen nested iteration But here there is no different iteration We are just looking at its position And store it So is this understood now? Fine I will be making some announcement Regarding projects tomorrow But the batch formation I have had some issues So I have shared that with some of the batch leaders I wanted balanced batches In all the lab groups So if you say lab batch 01 Lab batch 02 Then five teams which have to be formed I have said that they should be balanced I have found that some students are left out They are not part of any group Any team Is there anybody here who is not part of a team? Okay, 1, 2, 3, 4 This problem happens because if you have missed some lab turn And you are not physically present in the lab Then the people may not be able to assign Because an absent person is not counted generally So I have given two more days Tomorrow and day after By which time the team membership should be formed up So discuss with your team leaders Which batch or which particular team you would like to join They will all have the names of all the people Set up some mechanism But by Tuesday night The team membership should be decided Tomorrow I will discuss more about the project And then we will get to know that Next slide How do you know that? It will end with the life I thought End of a line Actually in a text file End of a line is written by backslash n In a text file Yes, however However You have given that backslash n The backslash n will generally not reach your program The function which reads the string Will chew up that backslash n If you are reading a text file Then you will not see backslash n coming into your program at all The input function c in will heat up that backslash n So you will never see a backslash n read Using the normal input operation c in However there are input functions Which will read every character from the string No matter what character you have given When we discuss that You will see that backslash n will get in In fact one fundamental problem of string handling In just one second This is a very important point that is making Although the whole class should know it Let you be the first one to know this In a normal c or c plus plus string If you have a character array This will end with backslash n This is the normal text line in c c plus plus Any text line is terminated by backslash n However in Microsoft environment The text line is not terminated just by a new line character It is terminated by carriage return and line feed character So that is called c r l f d limited character string It has two characters at the end of every line One is called carriage return One is called line feed The line feed is new line character This wording comes from a typewriter So you see in a typewriter When you type in a typewriter And the line ends So what do you do? Once you do this Then it goes forward And then the entire cylinder comes from here to there So it is called line feed And when you bring the entire cylinder back It is called carriage return So you have returned the carriage So with this your typewriter position You come to the first position And then to the next line The symbol of a typewriter is carriage return line feed And in Microsoft environment In the end of the sub string Carriage return and line feed is added But the Unix that was mentioned by Microsoft They said that I am done with the line New line is enough Now how do you display this new line character? You can see it on the terminal or printer You don't just go to the new line If you go to the new line After that if you give your new line Then it will come here After that if you give your new line Then it will come here So you don't just go to the new line You have to go to the new line So when you say end L See out end L So actually the C++ program Not only puts you on to the new line It also puts you at the beginning of the career Now this separation why I indicate If you have created a text file in Microsoft environment It will have this If you have created a text file in Unix environment It will have only this It is fun to try and read a text file Created in Unix environment using some Microsoft It will look very gibberish or funny So you have to open it in a word processor Or word pad which understands this problem These are nuances because different people Have written those programs And everybody has made one's own assumptions Anyway So this is just an interesting stuff I thought I would tell you So ordinarily you will not see new line inside your text But we shall see functions which read all characters Including new line characters And just ignore the characters from the text file Correct When you use get line Oh you are reading characters one by one Then you can actually test for backslash end If backslash end has come that means the line has ended You are reading characters one by one You are not reading get line Or you are not reading individual string If you are reading one character at a time Then backslash end will be a character Thank you very much