 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can perform file concatenation operation in C programming. Before starting, you can note how you can search my YouTube channel. You can type my name Sanjay Gupta in YouTube search. My channel will be available there. You can watch various programming related videos here. Now I am going to implement solution of this problem. So first of all, I am going to include two header files. First is stdio.h and second one is stdlib.h. Now I am going to define main function. Inside main function, I am declaring two file pointers f1 and f2 because I will be going to open two files. Now character variable ch is declared. Now I am going to open first file with the help of f1 file pointer. Name of file is file1.txt and I am going to open it in read mode. Now I am going to open second file whose name is file2.txt and I am going to open it in append mode. So I have opened two files, file1.txt and file2.txt. I am going to copy contents of file1 into file2 and file2 will be having its own contents as well. So that's why I have opened second file in append mode so that its previous contents will be saved or preserved and new contents of file1 will be available at the end of file2. So the finally output will be available in file2.txt. Now I have to check whether both the files are open or not. So this condition will be checking whether f1 is having null or f2 is having null. If any one of this file pointer is having null value then condition will be true and printf will print this error message and then exit will terminate execution of the program. So this way I have opened two files and I have checked them whether they are open or not. After this if condition I have to apply a loop. So in this loop condition is 1 which is always true so you can say this loop is infinite loop. In this infinite loop I will be reading contents of file1 and those contents will be stored inside file2. Remember that file1 is opened in read mode and file2 is opened in append mode and both the files will be having some contents inside them. So now I am going to read contents of file1 with the help of fgetc function. So fgetc will be reading a character available in f1 file and that character will be stored inside ch. Now I have to check whether the received character is EOF or not. EOF means end of file. So it represents that file has reached to an end. So if ch is equals to EOF then I can break the loop. Otherwise I can call fputc and I can copy this ch into second file that is f2. So this way fgetc will be reading a character from f1 that character will be stored inside ch. Then ch will be checked for end of file. If condition is false then fputc will be storing that character into f2. And file2 is opened in append mode so that its previous contents will be saved and new contents will be stored at the end of this file. So this way file concatenation operation will take place. Now after completion of these operations I can close both the files and then I am writing return0. So this is the complete implementation of the program. Now I have to create these two files file1 and file2. And my program is saved in c drive tc folder bin folder inside bin file is saved with test.c. So these two files file1.txt and file2.txt must be available in this path. If you are saving your .c file in any other path then you have to create file1.txt and file2.txt on that path. So now I am opening notepad. Here in this file I am typing sanjay that is my first name. I am saving it in c tc and bin and name of this file is file1.txt. It is already available so I am going to replace it. So file1 is created now. Now I have to create file2. Here I am typing gupta this is my last name. Again I am following the same path c tc and bin folder. Name of this file is file2.txt. So this way I have created both the files. Now I am going to bin folder c tc and bin. Here I am typing f. So the files which starts from f are available here and you can see file1 and file2.txt are available here. I am opening file1.txt it is containing sanjay. Now I am opening file2.txt it is containing gupta. Now I am going to execute a program which I have implemented for you. So after execution file1 content will be available into file2. So the program has executed properly. It is not showing anything because the contents are transferred into a file. Now again I have to move to the folder bin. Here file1 and file2 are available. So I have opened file1 it is containing the contents which were available in this file that is sanjay. Now I am going to open file2. So you can see here earlier it was having gupta only. Now it is having sanjay also sanjay is available in file1.txt. So file2 is having contents of its own as well as contents of file1. So this is the concatenation process which is available in this C programming. So I have demonstrated you how you can concatenate contents of two files into a single file with the help of file handling in C programming. I hope you have understood how I have implemented this code in front of you. If you want to watch more programming related videos you can search my name sanjay gupta in youtube. My channel will be available there. You can watch various programming related videos there. You can also download my android app tachymus which is available on play store. Thank you for watching this video.