answersLogoWhite

0


Best Answer

#include #include int main() { FILE *fs1, *fs2, *ft; char ch, file1[20], file2[20], file3[20]; printf("Enter name of first file\n"); gets(file1); printf("Enter name of second file\n"); gets(file2); printf("Enter name of file which will store contents of two files\n"); gets(file3); fs1 = fopen(file1,"r"); fs2 = fopen(file2,"r"); if( fs1 == NULL fs2 == NULL ) { perror("Error "); printf("Press any key to exit...\n"); getch(); exit(EXIT_FAILURE); } ft = fopen(file3,"w"); if( ft == NULL ) { perror("Error "); printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } while( ( ch = fgetc(fs1) ) != EOF ) fputc(ch,ft); while( ( ch = fgetc(fs2) ) != EOF ) fputc(ch,ft); printf("Two files were merged into %s file successfully.\n",file3); fclose(fs1); fclose(fs2); fclose(ft); return 0; }

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

hi friends this is bilal ahmed shaik from vijayawada persuing MCA -1st year in NRI(agiripalli)

i think for this question the program might be like this

--------------------------------------------------------------------------------------------------------

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void main(int arg,char *arr[])

{

FILE *fs,*ft;

char ch;

clrscr();

if(arg!=3)

{

printf("Argument Missing ! Press key to exit.");

getch();

exit(0);

}

fs = fopen(arr[1],"r");

if(fs==NULL)

{

printf("Cannot open source file ! Press key to exit.");

getch();

exit(0);

}

ft = fopen(arr[2],"w");

if(ft==NULL)

{

printf("Cannot copy file ! Press key to exit.");

fclose(fs);

getch();

exit(0);

}

while(1)

{

ch = getc(fs);

if(ch==EOF)

{

break;

}

else

putc(ch,ft);

}

printf("File copied succesfully!");

fclose(fs);

fclose(ft);

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

main()

{

FILE *fs,*fd;

char c;

fs=fopen("copy.c","r");

if(fs=NULL)

{

printf("source file cannot be opened");

exit(0);

}

fd=fopen("destination.txt","w");

if(fd=NULL)

{

printf("target file cannot be opened");

fclose(fs);

exit(0);

}

while(1)

{

c=getc(fs);

if(c=EOF)

break;

else

putc(c,fd);

fclose(fs);

fclose(fd);

printf("file copy operation performed sucessfully");

}

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to copy the contents from one file to another file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


How do you put a table of contents on a PowerPoint?

First you copy and paster your table of contents on the slide.Then You make the talbe of contents into a font that will fit the powerpoints square.


What is the difference between cut and a copy command?

a copy command would copy the contents of the selection and when you paste it somewhere else, the original contents would still be there. the contents would be available in both the original location and the new location a cut command would remove the contents of the selection and when you paste it somewhere else, the original contents would be lost. it would be available in the new location only.


Write a program to copy the value of one string variable to another variable?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.

Related questions

How do you copy the contents of a youtube playlist into another?

A new web tool called Copy YouTube Playlists will show you how to copy the contents of a YouTube playlist into another.


Write a program to copy the contents of one file to another?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int main(int x,char *a[]) { FILE *fp1,*fp2; fp1=fopen("input.txt","r"); fp2=fopen("output.txt","w"); while(!(feof(fp1))) { fputc(fgetc(fp1),fp2); } fclose(fp1); fclose(fp2); return 0; }


Write a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


C program plus copy of string to another?

strcpy


How do you copy music files to a memory card from a memory stick that is write protected?

The fact that the memory stick is write protected will not prevent you "reading" the contents. Thus there is no problem in making the copy from the stick to the memory card.


Is fill handle used to copy contents in Excel?

A fill handle can copy anything and in different ways. It can copy contents and it can copy formulas and it can create fill series.


Write a c program to copy two strings using pointers?

nahi malum


How do you copy from computer to disc in windows xp?

The best way to copy files from a computer to a disc is to write the same. Use a burning program to write the disc with the files that you want.


How do you copy the contents of a movie DVD?

You can use E.M. Free DVD Copy to copy the contents of the movie DVD, following the steps shown in the Related Links.


What is the extra copy of a program or document?

Get file from another computer, across a network


What is a copy cell in Excel?

When you copy a cell, you copy the contents of the cell. Excel allows you to paste those contents in a variety of ways. For example, you can paste either the cell contents (like a formula =A1+B3) or the cell value (like 143).