Guest User

Untitled

a guest
May 26th, 2023
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[]) {
  4. // Check if the correct number of command line arguments is provided
  5. if (argc != 3) {
  6. printf("Usage: %s <input_file> <output_file>\n", argv[0]);
  7. return 1;
  8. }
  9.  
  10. // Open the input file in read mode
  11. FILE *input_file = fopen(argv[1], "rb");
  12. if (input_file == NULL) {
  13. printf("Error opening input file.\n");
  14. return 1;
  15. }
  16.  
  17. // Open the output file in write mode
  18. FILE *output_file = fopen(argv[2], "wb");
  19. if (output_file == NULL) {
  20. printf("Error opening output file.\n");
  21. fclose(input_file);
  22. return 1;
  23. }
  24.  
  25. // Copy the contents from the input file to the output file
  26. int ch;
  27. while ((ch = fgetc(input_file)) != EOF) {
  28. fputc(ch, output_file);
  29. }
  30.  
  31. // Close the files
  32. fclose(input_file);
  33. fclose(output_file);
  34.  
  35. printf("File copied successfully.\n");
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment