1.CP (copy) file path to copy already exists
The code to implement the CP command is as follows:
2#include <stdio.h>3 4 //because you want to get two paths in the command, use the two arguments of the main function 5 intMainintargcChar**argv) { 6 7 Charbuf[ -]={0}; 8 9 intSize=0; Ten /*int buf[100]={0}; represents a single store in an array of four bytes. If the data we took from the original file > is 3 bytes, then we can't put it in.*/ OneFILE * p_src=null,*p_dest=NULL; A - if(ARGC <3){ -printf"format command error \ n"); the return 0; - } - - //the idea of copying 1: Read the original file into memory, and then write the new file. The original file may be very large. + //the idea of copying 2: Ants move -P_src=fopen (* (argv+1),"RB"); + //argv represents an array of pointers, A //the first pointer in the pointer array is the./out file, and the second pointer is the original file path at - //case of branch handling open failure - if(!p_src) { -printf"original file open failed \ n"); - return 0; - } in -P_dest=fopen (* (argv+2),"WB"); to + if(!p_dest) { -printf"new File open failed \ n"); theFclose"p_src"); *P_src=NULL; $ return 0; Panax Notoginseng } - the while(1){ +Size=fread (BUF,sizeof(Char), -, P_SRC); A if(!size) { Break;} theFwrite (BUF,sizeof(Char), size,p_dest); + } - //How many data you get from the original file, and how many numbers you write. $Fclose"p_dest"); $p_dest=NULL; - -Fclose"p_src"); theP_src=NULL; - Wuyi the return 0; -}
View Code
2.tar command
Use the ZCVF option to package (package multiple files into a single compressed file).
Use the ZXVF option to restore (Restore a large package of compressed file content to a normal file).
Error Correction: line 22nd of the code should be./a.out file
cp&tar& using C language program to realize CP command effect