Hello and welcome back to this practicals module…. and here we have come with a new problem in this flow, problems name is joining two strings. How to join the two strings how to put the gap in between them if we want to write ”Hello world”, which is a basic statement, if we want to print it and “hello” is stored in some other string and the “world” is stored in some other string. What we will do is if we want to print both the strings data in one line together, at that time we would be using this entire programme where our output that will come, will be hello, space, world. So, in this way “Hello World” will become a complete sentence and the way it will be printed, it will seem that this is a complete one string, even though we have joined two strings over here. We have attached to them. So, this program will be a completely basic and very easy, because we will be making use of a function, which function is that we will see in the program. So, without any delay, we will start this program joining two strings and we will see how two strings are joined. So, now, we will go into our text editor, which we have come and the first thing over here in any program that is writing the preprocessor command which we have used over here and we have used two preprocessor commands over here, the first one is stdio.h and the second one obviously string.h one which is the header file, it is the library, we have used it over here. Why have we used string.h over here because we are going to use string related one function over here, that's why we have included string.h over here. So, now, we have spoken about preprocessor commands. Now, we will go ahead and see how our main function is working here. So, in the main function, we have to write all those things which we will require to join the two strings. So, first of all, we will be requiring two strings together. So, which are the two strings, which we have to join here, we have to use to join. So here we will take one string’s input and here you can see that we have made s1named string because we have kept the character data type. Ahead of it we have put the square brackets and we have not defined its size. Instead of defining its size we have directly initialised it. With what? With the C programming statement. So, this was the first string that we have to use in this entire program. In the same way we will take another input of another string, which is s2 string and the input that we have taken in it is “by Learnvern”. So, what we have to do here is s1+s2 because of which the complete statement will come our which will be “C programming by Learnvern”. So, if we have to print this kind of a statement, we will have to join these two, we will have to concatenate. That's the reason why we are going to use our string concatenate function, which is written in this way with the syntax is strcat, after writing strcat, we will have to pass both the strings in the function’s parameters. The first string that we pass comes first. After that we put a comma and pass the second string. That comes on the second number. With our 1st string, the addition of both the strings stores there. That’s why the addition, the product that is coming after adding the two. If we want to print that what will be basically do? We will print our S1 string. Because in strcat function we has first pass S1. That’s why with the help of printf function we are printing S1 string. And in this we will print concatenate string equal to S1 and in S1, whatever strings will come that will get printed over here, you can see that we have only written c programming in S1. But when we concatenate with S2 and then we print it, what we will get then that we will quickly understand over here. So, here we are getting some error, once again we will close it. Here sometimes our compiler misbehaves, when it misbehaves, what do we do in that situation is we can close this terminal and try to run it again. If you want to run it again, we will go here on the run code. And now we will see if it is able to process our code or not. So, here again we are getting an error, there is no problem we will again write gcc command and now we will try to run it. So now we have passed the file’s name over here and we have even written gcc. You can see that this has got completely compiled. Now we just have to run it. As soon as we will run it, you can see that output is coming out over here. The desired output that, yes we want the same output, apart from this if something comes, some error comes, we will not be able to face it. So, the desired output that we had decided that's what we are getting over here and the concatenated string that has been made, that is C programming by Learnvern. So, earlier in S1 only C programming was been written “by Learnvern” was in other string. But when we made the use of strcat, when we made use of string concatenate function. In that case, this entire string “C programming by Learnver” we have printed it through S1. In this way you concatenate two strings, this was an easy and a shortest way. Along with this you can use different functionalities and concatenate strings. You can practice those thigns on our own. You can compile these things in your computer and see how this string concatenate function works. Along with this, there are strings apart from these, there are logics apart from these in which we are concatenating two strings, we will definitely execute it and we will implement it and then we will get a complete picture, how the concatenate works. So, you practise string concatenate function and we will meet you in the next video with a new problem, till that time thank you so much.
If you think that there is any part of this video or this topic, you might have not understood then you can ask us any query or question related to that topic without any inhibition.
You just have to go on forums.learnvern.com, you have to
type your query there in your own language and we will come up with the
solution or the answer as soon as possible in your own language.
Apart from this if you wish to have a discussion on any topic.
Even that you will be able to do on forums.learnvern.com.
Share a personalized message with your friends.