 Suppose, instead of this, I say while this while statement do you understand? What am I doing? I am reading a character converting it into a numerical value because this is integer and I am assigning it to S i which is i equal to 0. So, initially S 0 will get this value. Since this expression has a value which is assigned the value of this total thing itself will be the ASCII code of whatever character I have read. That will get compared with capital X. If that is not equal to capital X, this condition is true. If i is less than 100, this condition is true. I will come down. Inside what will I be doing? I will actually be saying just i equal to i plus 1. So, I go back again. So, notice that earlier I was reading the character inside the loop, assigning it to S i and increasing S i, increasing r. Here, I am reading it in the while condition itself. Assigning it to S i, both the jobs are done. I am actually cheating the while statement. While statement, condition is written. In the name of condition, I am writing assignment statement. That is permitted. It is perfectly valid because the condition is still there. Namely, is all of this not equal to capital X. What is all of this? All of this is what was the value which was assigned in the expression. So, if that value is not equal to X, the condition is true. Now, instead of doing i equal to i plus 1 here, suppose I put i plus plus. i plus plus is called post increment. Post increment means the current value I key is used. Use it and execute the whole statement. And when that statement is executed, when you do something ahead, the value of I key increases. So, first use the current value of I. Do the entire statement. And when you finish executing that statement, before going to the next statement, change i to i plus. So, notice that here the value that will be actually used will be 0 only. I plus plus is also written, so i equal to 0 at that time. Zero value will be used here. Is this statement not over? Now, this has to be assigned, this has to be assigned. Not equal to X, it has to be compared. And, and is written. Before that, I have to check less than 100. At this time, what is the value of I key that is original? Till now, the value of I key has not changed. Although, we have written i plus plus. In this whole execution, I will remain 0. Only when I completely evaluate this condition and find out it is true or false. If it is true, I have to go inside the loop. If it is false, I have to get out. But the moment this condition is evaluated, before doing anything, I will be now increased. That is why it is called post increment operator. So, it is incremented post everything else that you have done. Whatever you have to do, after finishing, increase the value of I key. That is why after writing like this, I do not have to write I equal to I plus 1. In one iteration, everyone will read it. Why did you write S i minus 1 here? Suppose, I equal to 0, I have read the value. This condition is correct. Now, I have to print it. But the value of I is 1. I plus plus was written. When I come here, the value of I will be 1. Now, I will not print S1. I will not read S1. I have read S0. That is why I have come here. If you do not want this, you can do this. You can write it separately. Just put semicolon here. While condition semicolon. There is no body. The iteration itself contains instructions to do something. What are you doing? In this condition, you are reading a character, assigning it to S i, incrementing it. Keep doing it till you get this. So, that means when this iteration completes, it is not a single statement. It will execute 20 times if you type 20 characters. When you come here, all characters have been read up to X. Now, whatever is the value of I is the value of N care. You can assign it. And now, if you want, you can run a for loop. Is that okay? So, you have come out of this iteration. This iteration has read the entire array. Now, you are printing it out. Earlier, I was trying to print inside the same iteration. Now, I am printing it outside. You can run this in a small program and see if it works. Now, one step ahead of this. Until now, we were reading the value of the as of the character. Now, we want to keep the character in the array with the characters. There is one string. There is one word. I, N, D, I. How many characters are there? Five. Now, either I put five variables like X1, X2, X3, X4, X5, type of character and put each character in each one. There is no meaning in that because any word can be long or small. So, for this, the array is used. So, if we write here, say some word. Now, how much will be its size? Again, the same question. If I write five, then how many characters can come in it? Five. If I write ten, then ten. If I write fifty, then fifty. So, generally, one word is not longer than one line. That is why we call it word 80. Now, we want to keep this character in word 80. So, we keep iteration in word like that. We used to capture the value of Ascii. Now, we will put characters in word i. But, later we will know how many characters are written in this word. Sometimes we will write in India, sometimes we will write in Hau, sometimes we will write in U, sometimes we will write in Ganapati. Now, there are different characters in each word. How will you know how many characters are written in word? When you are reading, then you can count. But, you have read it, your program has come forward. How will you remember how many characters are written in the word? Because, once you have read it, it has come forward. For this, C++ provides a special provision. Character arrays are very special. How will you keep track of how many characters are there in the string? Because, depending upon whether I enter this, it will have three characters. This will have three, this will have seven, this will have five. How will I know in general? If there is one string, car, array, something, and something is put there, how will you know how many characters are there? Because, you see, you may even want to keep a blank inside. So, there is no way you can determine how many characters are there in the string. So, for that, C++ has a special provision. What C++ says, you want to store in an array. This is the array word. And suppose, I am wanting to put this here. In 0th element, you keep i. In 1st element, you keep n. In 2nd element, you keep d. In 3rd element, you again keep i. In 4th element, you keep a. Now, the word is complete. Now, in 5th element, you keep 0. So, this is a special. This 0 is not symbol 0. This is not 0. This is absolute 0. This is written as backslash 0. Backslash 0 means absolute 0 value. As per the code table, there is 32 space. There is 48-0. There is 49-1. 0 is nothing. No symbol is 0. So, you keep absolute 0 value at the end. This is a convention in C++. That means, if you want to store characters in an array as a word, or in a string, whatever character. Later on, you want to find out how many characters you had put. The convention is, whenever you put characters, you should put a backslash 0 at the end after you finish. So, you will read, let us say, I and D, I, A, and you will have to put this backslash 0. Or some input statement will have to put this backslash 0. Something of that sort will happen. What this means is two things. Suppose, tomorrow, I store this word, say, you. So, how will the word array look like? What will be 0th element? Why? What will be 1st element? What will be 2nd element? You. And 3rd element? Backslash 0. We will have to write this. Now, there are two or four words, one word, two words, how many are there? Now, you have ever assembled any word in it. After that, at any point in the program, at any time, you can examine that array. Where is the backslash 0? Wherever backslash 0 is, up to that is a valid string. Because backslash 0 is not a valid character in any characters. So, this is a convention with C++. All strings in C++ are stored in character arrays and the last symbol stored inside is always backslash 0 to, say, end of array. It has one implication. If you have declared the array size to be 80, then that means ordinarily you can put 80 symbols inside, 0, 1, 2, 3, 4, up to 79. But then, you will not be able to put backslash 0 because there is no space. So, generally, if you declare an array of size 80, how many characters you can store inside? 79. Because 80th place, at least, must be reserved for backslash 0. If you put five characters, no problem. 0, 1, 2, 3, 4, at fifth position, you can put backslash 0. So, backslash 0 means you have to store one character less. But that is okay. You can always, if you want strictly 80 character strings, you declare size of array as 81. Normally, no one does that. 80, 100, 256, something you declare. But you know that a single character string should be less than this. Okay? Now, I will give you another problem. Read the question first. There are two words. Two words of the type in the input. Okay? Suppose there are two words. These are two words of the type. You do not know what type it is. I can write my name. What is guaranteed? What the problem says? The two words are separated by a blank. That is, whatever type it is, after ending a word, it will type a blank. Exactly a blank type. Then the second word will type, after the second word, it is a blank type. That is, there is a blank here as well as a blank here. So, I have typed in two words. I do not know how many words there are in each word. Whatever the five, ten, fifteen, whatever it is, after that I will type a blank. Then I will type five, ten, other letters, another word. I will type a blank. Your job, read this much portion. Whatever is the first word, this or this or this, put it in an array first. And second word, this or this or this, put it in the array second. Simple job. How will you do it? Let me give you some declarations. So, I have one array first, another array second. Please understand the algorithm. First, understand what you have to do. You have to start studying from the gatecars. First, you have to read the character. First, you have to put it in the first element. Second, you have to put it in the first element. You have to put it in the second element. You have to put it in the third element. You have to put it in the fourth element. Where is the blank? It is over. You have to get out of the iteration. In that position, you have to put the backslash zero. Because then the entire character string will become an array. After doing that, the only blank is equal. The next character is assembled in the second word. Then after that, you will put the second zero in the element. You will put it in the second element, in the second element, in the second element, in the third element, in the fourth element. The blank is over. Then you put the backslash zero. It is over. Okay? So how will you write this program? We use the same one that was written earlier. Okay? Let us see what this statement will do. I have to write i equal to zero here. Okay? While first i plus plus equal to gate care. What it will do? Gate care will read a character. It will assign it to first i. i is equal to zero. It will check whether this character was blank. If that was blank, I have to get out. If it is not blank, I have to repeat itself because there is no other body. Next time, i will become one. Next character will be read in i equal to one. So I will read it in array first one. It is not blank. First two, first three. If this input is given, when will it be blank? At what value of i it will be blank? This is i equal to zero. This is one, two, three, four. i equal to five will be blank. So when I come out here, I have come out because I had received a blank here. And at that time, I would have read that and put it in first. So you look at how the first has been assigned values. Let us say I have typed hello. Let us execute this program. While i equal to zero. So this is zero element. First i plus plus gate care. It will get me h here. And i will become one. Next again, gate care. It will get me e. I will become two. Next it will get me l. I will become three. Next it will get me another l. I will become four. Next it will read o. I will become five. Next it will read this blank. Please note, right now blank is not being checked. It is being assigned to my array. So here a blank will go away. Fifth element. After this it will be checked. This is blank. Get out. But before leaving, increase the i. i becomes six. Right? So when we get out, i will be equal to six. Now I have assembled all the words. But I have to put a backslash zero at the end of the character's rail. Where should I put backslash zero? I should put it here where it was blank. Because that is not part of the word. Word is finishing H-E-L-L-O. Now I know that when I come out here, whatever is the value of i, it is one more than the position where I have to put that backslash zero. So I will say i is equal to i minus one. Or more importantly, I will say n char one is equal to i minus one. Where n char one is the length of first word. n char two is the length of second word. That is my assumption. So when I assign n char one equal to i minus one, in this case, what will be the value of n char five? And that is correct. One, two, three, four, five. There are five characters. n char one is five. But I have to put a backslash zero. So where should I put backslash zero now? Whatever is the length? Since the elements are zero, one, two, three, four. So zero, one, two, three, n char minus one, characters are there. n char is the position where the backslash zero is. Are you sure that I would have assembled this properly? I have assembled the first word. Now I want to assemble the second word. Where will I assign the second word? Again I will have to start with i equal to zero. And again do the same thing while this time, second, i plus plus. Sorry, I will just come back. Sorry, how? When you are saying get care here, you are reading a character. You do not know what that character is. At which point will you assign backslash zero? Please remember, till you complete this, this is not a single statement. There is actually something, something and body. This is iterating. Only when you finish the iteration, you know that there is a blank. Till then you do not know. How will you know if there is a blank until the entire iteration is over? So only after the iteration comes out, you will know that there was a blank, that is why you came out. Till then how will you know? So where will you assign backslash zero? At what value will you assign it? Will you assign backslash zero here? Will you assign it here? You have to keep reading the character. You have to assign backslash zero here. But how will you know? Till the time you read the blank, you do not check it. And as soon as you check, the iteration comes out. So both of us cannot be together. So check and come out. Or stay inside. So backslash zero has to be done after reading all the characters. It cannot be done in between. Only thing is because i is incremented here, you will come out earlier. You will come out, sorry, when i will be one more than necessary. That is why you have to subtract one. Now you can do exactly the same thing here. And this time again say now, n care two equal to i minus one. And second n care is equal to... So now let me ask you a question. Suppose i have not said read two words. But i have said read five words. Each separated exactly by one blank. Are you not going to write similar statements again and again and again? If you want to read five words, you will write it five times. If you want to write five words, you will have to write first, second, third, fourth, fifth. Then i said read ten words. Then you will write a program again. That is why you have to read so many words. You do not know exactly. So instead of storing everyone in different areas, if i make two dimensional matrix, once in one row, second in the second row, third in the third row, fourth in the fourth row. Will it not be better? So let us extend this program now. It is not necessary. I want to store forty words. Because, first, what was the problem in this? It is typed in one line and separated by blank spaces. How many words can be typed in one line? There is a line of eighty characters. If you typed in one character, then you will do forty because both sides want blanks. So you can give more than forty words. But believe me, you did not do forty, you typed in one long word. So how many characters can be eighty? So maximum number of words are forty. So an area of forty by eighty is good enough for me. I do not need anything more. Here we are saying now a problem is being redefined redefined. The problem is multiple words are typed in a single line separated by blank spaces. A blank. Read all of them. Now believe me, what I wrote here is like this. Hello world, how are you? How many words are there in this? Five. One, two, three, four, five. First there are five letters. Second there are five. Third there are three. There are three. It is arbitrary. Anything can happen. There could have been ten, five, seven, whatever. Now I want you to do the following. This is your array word forty by eighty. So what do I want? The word zero is zero. In that I want H, E, L, L, O, backslash zero. Isn't it? Yes, I want it. The first element of the word is first row. In that I want W, O, R, L, D, backslash zero. The second element of the word is H, O, W, backslash zero. The third element is A, R, U, backslash zero. And the fourth element is Y, O, U, backslash zero. There is nothing in the fifth element because the word is over. Now if I type ten words, then you have to fill ten words. Type two words and fill two. So the first problem was a special case. First name, second name were empty. Now the first, second, third, as much as you want, I want to store them. The general program of this is actually very easy as much as it takes. The first iteration that we wrote was to be written. But we have to repeat it again and again until the whole word is over. Until the whole word is over, repeat it. We think about the repetition outside. I have a maximum capacity of 40 words. So I am saying, I don't care how much words you type. I will provide for reading 40 words. Read 40 words from my side. So I have written for I equal to zero, I less than 40. I plus plus. Whenever I come here, then my 40 words will be read. Now every word I have to read in Ith row. But now J, this column is J equal to zero, J equal to one, J equal to two. I have to put one character. So what will I do now? Now I will put an iteration in it. Here first I will write J equal to zero. Since I forgot to declare, so I will go here and write J. Then I will write Y here. Now look, I am doing something different here. What am I doing in it? I am reading a character in Ith row and Jth column. And I am checking if it is blank. I am not incrementing it. I have come to J sometimes. What have I just done? So tell me when I will come here. If the character that I have read, if it is not blank, then I will come here. I will read the first character in Ith. If it goes in Ith, the word is zero, zero. It is not blank, that is why I came here. Now I have read one character that is not blank. So I have to read it further. So I will just write J equal to J plus one here. That means the value of J was zero. You have read it. If it is not blank, then you have come here. After coming here, you have increased J. You have gone back. Now it is zero. Now it is zero in Ith row. You will read the next character in Ith. That Ith is not blank. It will be read Ith. You will come in and write J equal to J plus one. It will be J2. This iteration will continue. Until when? You will read a blank after reading Ith. Now the blank that you will read here, then this condition is not true. You will come here. How much is the value of J at this time? The value of J was zero here. If it was not blank, then you have made it one. If it is one, then you have made it two. If it is two, then you have made it three. If it is three, then you have made it four. If it is not blank, then you have made it five. But when you will read the fifth, then it will become blank at that time. You will come out. When you came out, then how much was the value of J? Five. Whatever the value of J is, you have to put backslash zero in it. So if you have written here, world I J equal to backslash zero. Now it does not need to be reduced. The first program that we had written, we had written J plus plus here. That is why it was increasing there. Now it will come out at the last value when it becomes blank. So you have zeroed there. So this means that it has been assembled. If it has been assembled, then it has been reduced. Now you have to take the next word. That is, you have to increment i. Then you have to zero J. So now you will come here. If you come here, then what will happen if you come here? This is the iteration of the outside. Here you had started with i zero. Now it will become i equal to one. What will happen if it becomes i equal to one? This iteration will start again. i equal to one and j equal to zero. But the word that you will read now, it will go to world one zero, one one, one two. Next time it will go to i equal to three. Three zero, three one, three two. So all this will continue. The problem is that you have done hello world how are you. But it did not end. Because you have done so much to stop it. I have to read 40 words. Now see when i equal to zero, one two three four. Till then it is fine. If i equal to five, then what will happen? Think. If you come here, if i equal to five, j equal to zero. You read the first character. Now it depends on what type he has done here. Suppose he has typed blank. Then you will read that character. You will write blank here. You will come out of that loop. If you write blank, then you will do backslash zero. That means this word has happened that there is no word in it. Backslash zero has already come. It is a null string. It has no letter. But suppose that fellow does not type that. That fellow types enter. See this program is forcing you to type 40 words. Now do whatever you want. Give me 40 words till i am going to sit quietly. This is also not right. What we had said? Multiple words are typed in a single line. This means how word, how are you? After giving blank here, he will enter. This is expected. So if we modify the problem, that problem is now interpreted is you are typing words separated by blank. After the last word and a blank, you must press enter. Suppose we say that. Now what it means? I have read a character here. Let me write this j equal to j plus 1 here. When I come here, after the last blank, I would have put this into this area here. My enter will come at this point. If I can check for that enter symbol and say enter, how can I do that? Backslash n. But where to check? I have assembled what I have read. Now I do not have any character to check. You think about this problem. I will write a program. I would like you to take that program down and analyze it at home. You understand the problem? We are assembling the words together. But this program will read 40 words. Our problem is that it is written separated by blank in one line. We believed that after the last word, it would give a blank. But whenever it will enter, the program should terminate. The program should come out. How can we do that? Now I have understood how the program is easy. You can assemble 5 or 10 words. But you have to assemble as many words in one line then you have to stop. So I am writing a program. Read that carefully. And try to write that program using some other logic. If you find any other logic and try to write that program. You have understood the problem? I am typing words. After that, whenever I enter the program, I want you to understand that I am bored of my words. I don't want to type any other words. So whenever I am done, you have to keep as many words as you want. And tell me the number. So you can increment a variable by doing a number. It is simple. The value that you have got is as many words as you want. It was 0, then 1, then 2, then 3. So it is 0, 1, 2, 3, 4. You have read 5 words. But you have to print them at the end. And you have to print as many words as you want. So how will you do it? Write it down. If you have saved it, then write it later. Let's see it first. This is the same words 40 by 80. Here N words is a new variable. And tell me how many words we have read. Keep that in mind. I and J variables. Now I have written it a little differently. In this, I equal to 0. I have read the first character. Now I know that the first character will be a non-blank character. The first H of the word will be there. That is what we have said. If this is not a new line character then we will do this. Whenever this is a new line character we will come out. This means wherever we type a new line character then our program will come out. We will read each character. If that character is a new line then we will come out. This is the guarantee. When can a new line character come? After any word a blank will come and a new line character will come. This is our specification. So the first character will not be a blank. But this is our wide loop in general. Now it is written here. If it is written here, then what is X? It is a new line character. But if it comes for the first time then it is a valid character. If it comes later then it can be a blank. So here J is equal to 0. The first character will be checked by while X is not equal to blank. We have read X. Now X was not a new line character. Is it blank? If it is not blank then we have to put it in the current word. And the current is J is equal to 0. So whatever we have read X if it is not blank then we have put it in the word IJ. After that we have put J. We are assembling this. J was 0. We have put H in it. We have put J to 1. After putting J to 1 we have put a new character. We have put it in X. So this is the next character we will examine it. What character? So the second character E will come here. We will go back. E is X is not equal to blank. Yes it is not equal to blank. We have assigned E to the next character. We will read E, L, L, O. Now it will be blank here after L O. So whenever it is J is equal to J plus 1 we will come here. At that time what is the value of J? 0, 1, 2, 3, 4 and 5. When the value of J is 5 we have read the fifth character that blank came out. Not fifth, sixth character actually in fifth element. So the value of J is 5. So instead of blank we have to put backslash 0. The word IJ is equal to backslash 0. This word is complete. Now we have to go up by assembling the next word. So I is equal to I plus 1. So we have come here. The first character here we have not read it yet. The way we read the first character of this file we will read one more character here. This will be the first character of the new word. When we go here we will go back here. The first character will come here it will be blank. But when the last word will be read R, U, blank then we have done it from the blank to here. The next character that we will read will enter. When I will go from here I will say X is equal to backslash 0. Don't do anything. Whatever value will be I we have read that much. Because the value of I will be 5 and in element 0, 1, 2, 3, 4 we have kept the words. We have kept the number of words. You get this logic. Isn't it very simple and elegant? You can read as many words as you want till somebody say enter. Now I will leave you with one more food for thought. In real life the words we will write we will not put one blank. Sometimes we put 2 blanks by mistake. So now I will give you a sentence. Make this program that sentence is like this. Hello blank blank blank world blank how blank blank R blank U blank blank blank blank enter. And if you solve this problem solve another one blank blank blank blank hello. What you are telling me that I can enter any number of words in a line separated by blank. Now why should I print only one blank? It is my way of typing. Now you see the problem is similar. There are words separated by blanks. The result is also to be similar. You have to assemble these words in words 40 by 80 separate rows. But the work is harder. There could be any number of blanks. Now you have to think your logic was correct till now. 1 blank is completed. 2nd word end of line is completed. Now there is no trust when there is end of line. How long is there a blank? I will give you a third possibility to win. blank blank blank blank blank blank blank blank blank Show me the words. There is no word. You should be able to report zero words. Another possibility? Return to Ravadhyam. You didn't even give a blank. Your program should work in every condition. Now try to write this program. And this time please try to do it. Try to collaborate. This is not an exam. Try together with four people. Write a program and execute it in two conditions. Write five or two words. Take any sample. Think about it and ask your friends. And consider this to be a collective exercise. Try it yourself hard. Take anybody's help. But you must understand what is happening. And now resolve this problem. We will see that.