Write a program to implement the function of the file copy

tags: C language  Development language

Use FGETC to implement the file copy function

int main()
{
	File *fp; // Copy files
	 File *fp1; // copy file
	char ch1;
	fp = fopen("work.txt", "r");
	fp1 = fopen("work1.txt", "a+");
	if(fp == NULL)
	{
		printf("error\n");
		return 0;
	}

	if(fp1 == NULL)
	{
		printf("error\n");
		return 0;
	}
	
    ch1 = fgetc(fp);
	while(ch1 != EOF)
	{	
		fputc(ch1,fp1);
		ch1 = fgetc(fp);	
	}
		
	fclose(fp);
	return 0;
}

Intelligent Recommendation

Write a program to implement the function of the address book

Write a program to implement the function of the address book: code show as below:  ...

Read and write function to achieve a copy of the file

First, the function   size_t read(int fd, void *buf, size_t count); Function: Read the count byte data from the file fd and store it in the buf Parameters: count: the number of bytes expected to ...

More Recommendation

Use the input/output stream to write a program to realize the function of file copying. The form and operation function of the command line parameters of the program are similar to the copy function in DOS

Use the input/output stream to write a program to realize the function of file copying. The form and operation function of the command line parameters of the program are similar to the copy function i...

The system calls open/read/write to implement a file copy.

Function prototype int open(const char *path, int flags,...,/* mode_t mode */); returns the file identifier if successful; error returns -1; ssize_t read(int fd,void *buf,size_t nbytes); successfully ...

Keil calls the bat file, implement deletion, copy, encrypt file function

usage Open the "User" subtab in the following way You can see 3 triggers on the left: "Before Compile C / C ++ File": Trigger before compiling C / C ++ source files "Before Bu...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top