Pre-requisite: File Handling in C
Given the source and destination text files, the task is to append the content from source file to destination file and then display the content of the destination file.
Input: file1.text This is line one in file1 Hello World. file2.text This is line one in file2 Programming is fun. Output: This is line one in file2 Programming is fun. This is line one in file1 Hello World.
- Open file1.txt and file2.txt with “a+”(append and read) option, so that the previous content of the file is not deleted. If files don’t exist, they will be created.
- Explicitly write a newline (“\n”) to the destination file to enhance readability.
- Write content from source file to destination file.
- Display the contents in file2.txt to console (stdout).
Below is the output of the above program:
Time Complexity: O(N)
Auxiliary Space Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C program to reverse the content of the file and print it
- C program to print odd line contents of a File followed by even line content
- C program to Replace a word in a text by another given word
- C program to find and replace a word in a File by another given word
- Program to copy the contents of one array into another in the reverse order
- C program to check whether the file is JPEG file or not
- Lex code to replace a word with another word in a file
- Count of arrays in which all adjacent elements are such that one of them divide the another
- Number of visible boxes after putting one inside another
- Find the minimum number of rectangles left after inserting one into another
- Count pairs in array such that one element is reverse of another
- Convert one array to another using adjacent swaps of elements
- C program to invert (making negative) an image content in PGM format
- Value of k-th index of a series formed by append and insert MEX in middle
- How to Append a Character to a String in C
- Perform append, update, delete and range sum queries on the given array
- Append two elements to make the array satisfy the given condition
- Convert many to many mappings to maximum no of one to one mappings
- Write a C program that displays contents of a given file like 'more' utility in Linux
- C Program for Lower Case to Uppercase and vice-versa in a file
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet