 Hello friends, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to explain how you can print the words of a stream. So I will be explaining this concept with the help of two different methods. So before starting of the explanation, I want to share one information. If you go to detail or description of this video, you will find set of links related to playlists. Those are available on my channel and those playlists are related to C programming videos. So you can follow them if you want to watch both programming related videos. So now I'm going to explain this method number one first. So let's say we have one stream and the content is India. So reverse means we need to print this A, I, B, then M and then I. So this should be the output. So I am taking this as STR. So starting the program. So I am declaring a character array. Let's say it's size is 10. Now I'm going to take two variables, I and L, then print F, enter a string, then I'm going to read it through GATES. So STR, right? So this way I have received the input from the user. Now I'm going to first calculate how many characters are available in this stream. Because I need to print A first as output, then I, then B and so on. And in case of a string, we don't know how many characters will be entered by the user. But we know after input, the last character will be having null character after that last character. So we just need to identify where null character is available so that we can identify how many characters are there. So we can do counting in two ways. Either we can iterate a loop or we can use a predefined function that is STR array. So as of now I am going to use that predefined function. So this predefined function is available in string.h, string.h header file. So you need to include this header file, the whole main function. So I think this is very easy to write yourself. So this L will be having a total length. So in this case, we have total five characters. So length will be five. So we have total number of characters available that are five. So now you can see we have value L as five. So we can start loop from four. So here I am writing I equals to L minus one. I need to repeat a loop till zero and I minus minus. And here I can print for string C STR of I. So here you can see length is five. So five minus one will be four. So I will be initialized with four. Four is greater than equals to zero. That is true. So fourth index value will be printed on output screen and see it carefully. I am using percent C here. So percent C always print a single character on output screen. So it will print A then I will be decreased. So its value will be three. Three is greater than equals to zero. So STR of three is having I so it will be printed. Then again I will be decreased. So it will be two. So D will be printed. Then I will be one. So N will be printed. Then I will be zero. Again, this condition is true. So I will be printed and then I will be decreased to minus one. That time this condition will be false and the output will be in print. So this is the first method that I explained you in that case. We received as input a string in STR and then we printed its reverse. So here you can see we are printing that string in reverse order, but actually it is not having the contained in reverse on. So my method number two will tell you how you can reverse the locations of these characters within the string and then how we can print that string without any loop in reverse order. Right. So I'm using these. So for method number two, I will implement a logic to swap characters. So I will be wrapping these two positions. So I will be swapping with A and A will be swapping with I. So it will happen. And I will come through. Right. And this way I will swap these two and the middle one will not be so if we have odd numbers, if we have odd locations, so one swapping will not be done, but if we have even positions like if we have six characters, then all three will be swapped with other three. So this way it will be reversed. So this will be the output. Right. So India is reversed here and we can just print this SDR so that we can have output. So we can print this string without any loop. So now I will tell you how to swap the elements within the string. So I'm writing initial values. So this is the actual string that we need to reverse. So here you can see I have identified the length. So length is five. Now I'm going to start loop from zero. And here I'm using J as L minus one. And I'm declaring one more variable as J. And then I'm putting up 75. So here you can see I'm putting common between. So I started from zero and J is having L minus one. So J is having value as four. Right. And this is the loop condition. Then I plus plus or J minus one. So this is the loop. Then inside this loop, I'm going to apply the logic for stopping the characters. So I'm beginning one more character variable P. So P equals to SDR of I then SDR of I equals to SDR of J and SDR of J equals to T. So this way the characters will be swapped so that we can have reverse of string. So starting from the beginning. So I is below and J is four because of this. L is five, length is five. So five minus one. So J is four. Now check this condition. I less than J. It is two. Now the swapping will be performed. So A will be here. And I will move to here. Right. So in first rotation of this loop two characters are swapped. Right. Now I will be incremented. So I will become one and J will be incremented. So it will be three. So again, check this condition. I less than J. It is again true. So one index and three index will be swapped. So one is having N and P is having IXY will be here and N will move here. So two rotations are completed of this. Then I will be incremented to two and J will be incremented to two. Check this condition. Two less than two. It is false. So no further rotations will be taken place. So this loop will be terminated and you can see string is reversed with this loop. And after completion of this loop. You can print. Reverse equals two percent S and STI. So without any loop, you can directly print that string. So the actual string is being reversed through this logic. And we are printing that one. So the original order of that string is gone and the reverse one is available. So you can use that. So this was method number. So in some scenarios, you just need to print the string in reverse order. So in that case, you can apply method one. In some scenarios, you need to reverse the actual string in memory location. So in that case, you can do method number. So I hope you understood how we reversed or how we printed the words of a string that is provided by the user with these two methods in C language. And I hope you explain. Sorry. I hope you understood whatever I explained in this video. And if you want to watch more programming related videos, you can open my channel and go to playlist and see various variety of videos. Also, you can go to a detailed or description of this video where you will find links of various playlist related to C language on my channel. So thank you for watching this video. Thank you.