Write a C program to merge two files into a third file (i.e., the contents of the first file followed by those of the second are put in the third file).
Algorithm:
Step 1: Start Step 2: open a empty file in write mode. Step 3: if it is not end of file Step 4: write data into that file. Step 5: close the write mode operation Step 6: repeat the above process for second file. Step 7: now use concatenation operation to combine the files. Step 8: the contents of the file will be displayed in the third file. Step 9: Stop
Program:
#include<stdio.h> void concatenate(FILE *fp1, FILE *fp2, char *argv[], int argc); int main(int argc, char *argv[]){ FILE *fp1, *fp2; concatenate(fp1, fp2, argv, argc); return 0; } void concatenate(FILE *fp1, FILE *fp2, char **argv, int argc){ int i, ch; fp2 = fopen("files", "a"); for(i = 1; i < argc - 1; i++){ fp1 = fopen(argv[i], "r"); while((ch = getc(fp1)) != EOF) putc(ch, fp2); } }
Input & Output:
File1: studentboxoffice.in. File2: This is Computer Programming Lab. File 3: studentboxoffice.in. This is Computer Programming Lab.
-
UpdatedOct 21, 2014
-
Views16,053
You May Like
Write a C program to find the roots of a quadratic equation
.
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use switch statement
)
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write C programs that use both recursive
and non-recursive functions
- To find the
factorial
of a given integer. - To find the
GCD
(greatest common divisor) of two given integers.