Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <sys/types .h> #include <sys/stat.h> #include <sys/file.h> #include <unistd .h> #include <stdio .h>
  2. /* change to <sys/fcntl.h> for System V */ /* needed for perror function */
  3. /*
  4. * appendfile.c: append the contents of the first file to the second file */
  5. int
  6. {
  7. main (int argc, char *argv[])
  8. int n, infile , outfile ; char buffer [1024];
  9. ( argc != 3) { //Q: what does argc ( argument count ) mean? write(2, "Usage: ./appendfile file1 file2\n", 32); exit(1);
  10. }
  11. i f
  12. }
  13. /*
  14. * Open the first file ( file1 ) for reading */
  15. if ((infile = open(argv[1], O_RDONLY)) < 0) { perror(argv[1]);
  16. exit(1);
  17. }
  18. /*
  19. * Open the second file ( file2 ) for writing */
  20. if ((outfile = open(argv[2], O_WRONLY | O_APPEND)) < 0) { perror(argv[2]);
  21. exit(1);
  22. }
  23. /*
  24. * CODE HERE: Copy data from the first file to the second file */
  25. /*
  26. * Close the two files before exiting */
  27. close(infile); close(outfile); exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement