Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



C How to Program (3rd Edition)    (ISBN: 0130895725)


 

 List Price: $78.67
 Our Price: $78.67
 Used Price: $43.00

 Release Date: 16 August, 2000
 Manufacturer: Prentice Hall (Paperback)
 Sales Rank: 46,122

 Author: Harvey M. Deitel, Paul J. Deitel









More Info

 Copy File 2003-03-11 02:12:12
 
Category: source:c:files
Description: Very simple method to copy a file.
Platform: unix
Author: detour
Viewed: 13585
Rating: 3.8/5 (69 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
copy.c
/* copy.c written by detour@metalshell.com
 *
 * Very simple method to copy a file.
 *
 * http://www.metalshell.com/
 *
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

void pHelp(char *me) {
  fprintf(stdout, "Usage: %s <srcfile> <destfile>\n", me);
  exit(0);
}

int main(int argc, char *argv[]) {
  int inF, ouF;
  char line[512];
  int bytes;

  if(argc < 3)
    pHelp(argv[0]);

  if((inF = open(argv[1], O_RDONLY)) == -1) {
    perror("open");
    exit(-1);
  }

  if((ouF = open(argv[2], O_WRONLY | O_CREAT)) == -1) {
    perror("open");
    exit(-1);
  }

  while((bytes = read(inF, line, sizeof(line))) > 0)
    write(ouF, line, bytes);

  close(inF);
  close(ouF);
}
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?