 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how it performs string concatenation in C language. So before start, I just want to share one information. If you go to detail or description of this video, so you will find links of various failures related to C language. Now I'm going to start my explanation. So in this video, I will explain you string concatenation logic. So I'm not going to use SCR CAT that is redefine function. But I will tell you how this SCR CAT concatenate two strings. So I will be explaining that logic with help of loops. So here you can see two strings are available. S1 and S2. S1 is having my first name and S2 is having my last name. So I need to concatenate both and the concatenated result will be available into S1 string. So what I am going to do, I am going to remove this null from here and I will be placing one space in place of this null character. And after this here on seventh index, this G will be copied, then U, P, P, A and then at last it will be having null character. So before starting the build-off logic, I am just writing initial statement so that you will get to know how we can leave two strings from user. So first of all, I am going to write name and then two strings S1 and S2. Then I am going to declare two variables I and C, then a printf statement which will display a message and enter first string. So to leave that string, I am using getters, so getters S1 will leave that string. Then again one more printf, enter second string. Or in this case, we can also write here enter first name, enter last name. So this depends upon you what you write in printf. So this way with these statements, I am able to read a value of S1 and S2 from user. Now, first I need to rotate a loop so that I can move to this null position of S1 string. So for this purpose, I am going to write a loop which is started from below. Its condition is this S1 of I not equal to null and then I plus plus. So if this condition is true, then this loop will repeat and it will be implementing value of C by one. So initially I 0, check this condition S1 of 0 not equals to null. So S1 of 0 position is having S which is not equals to null. So C will be incremented by one. So I am writing logic here. So when we are on this position S, so C will be one. When we are on A position, C will become two. When we are on N, C will be three. If we are on J, C will be four. If we are on five, if we are on A, C will be five. When we are on my, C will become six. Then I will be pointing to this position null and in that case you need to check this condition. So in that case this condition will be false and this loop will be terminated. So after rotation of this complete loop, you can see. Final value of C is six. Final value of C is six, which is the last position or you can say null position of S1 string. And we need to identify that position on it because we need to remove null from S1 and we need to place a blank space on that position. So after completion of this loop, I can write this S1 of C equals to space. So in single quotes, I mentioned the space. So S1 string C index, that is six. So it will be having a blank space. So null will be removed and it will be having a blank space, right? Now I need to implement one more loop that will repeat according to S2. So I will repeat the loop starting from zero to null position and I will copy one by one each character to these positions, right? So this time I need to start from here, from seventh index because on sixth index I have already stored space. So after putting this space, I am again incrementing value of C. So this time C will become seven. So current value of C is seven. Now I am going to implement one more loop that has i equals to zero. S2 not equals to null is the condition and then i plus plus. So here you can see I have used S2 of i. So now loop will depend upon this string. So if null is not available, then it will repeat. If null is available, it will be deleted. And I need to copy value of S2 into S1. So right-hand side contained will be copied at the right left-hand side position. So S2 of i value will be copied to S1 of C position. And then I am going to increase value of C, right? So now I am going to iterate this. So initially i is zero. Check this condition. S2 of zero not equals to null true because S2 of zero is having G. Then S2 of zero will be copied to S1 of C. So what is the latest value of C? So six and then we incremented seven. So latest value of C is seven. So S1 seven position will be having S2 of zero position value. So G will be copied here. G will be copied here. Then C will be incremented to eight. Then I will be incremented to one and check this S2 of one position. That is you, which is not equals to null. So again it is true. S1 of one position will be copied to S1 of eight index because right now C is eight. So you will be copied here. Then C will be incremented to nine and I will be incremented to two. So C incremented. I incremented. Now check a second index value. That is P not equals to null. So P will be copied to S1 at C index. So he will be copied here. Then again, C will be incremented. I will be incremented. So check a third index of S2. It is having T which is not equals to null. So T will be copied again and it will become 11 and it will become four. So S2 of four index will be copied to S1 of 11. So A will be copied. Then it will become 12 and it is five. So S2 of five index is having null. So null not equals to null. This time this condition is false. It means null will not be copied and this loop will be terminated. And the final value of C is 12. Now at 12 index at this position, we need to insert a null character because if we don't insert null, then S1 will not become a string. So after completion of this loop, I am putting this. S1 of C index will be having null. So S1 of C is 12. So 12 index will be having null. So this way you can see both strings are concatenated into S1. It is also having a blank space and then last thing then null again. Now after this, you can use a print test. And you can print the result like this and close the main. So this way you saw how I implemented the logic. So first I find out the last position or null position of S1. Then I place space. Then I copied second string into first string at the end and then I printed the output that is available in S1. So this way I explained you how we can concatenate two strings in C language. I hope you understood whatever I explained in this video. And if you want to watch more programming related videos, open my channel, go to playlist and see various videos there. Also you can go to detail or description of this video. So there I have pasted links of all the playlist related to C language. So you can follow them as well. So thank you for watching this video.