Wednesday 28 September 2011


COPY ONE FILE TO ANOTHER FILE

Aim
  
To write a C program to copy one file to another.

Algorithm:
1. Start the program.
2 Open the source file in read and write mode.
3. Create the new file and open with new file name.
4. Read each character from the source file and write the character into the destination file until end of the character.
5. Stop the program.

Program:
#include <stdio.h>
#include <fcntl.h>
#include <types.h>
main()
{
  
 int fd, fdl, fd2, n;
char buff[80j;
fd = open(”Bensam.txt”, ORDWR);
fd2 = open(”Jovita.txt”, O_RDWR);
Iseek(fd,0,0);
while((n=read(fd, buff, I ))>O)
{
write(fd2,buff,n),
}
printf(”File copied”);
}

Content of Bensam.txt
This is Bensam

Output: 
File Copied
Content of Jovita.txt
This is Bensam

Result :
Thus the program is written and executed to copy the content of one file to
another file.

0 comments:

Post a Comment