Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(int argc, char *argv[]) {
- // Check if the correct number of command line arguments is provided
- if (argc != 3) {
- printf("Usage: %s <input_file> <output_file>\n", argv[0]);
- return 1;
- }
- // Open the input file in read mode
- FILE *input_file = fopen(argv[1], "rb");
- if (input_file == NULL) {
- printf("Error opening input file.\n");
- return 1;
- }
- // Open the output file in write mode
- FILE *output_file = fopen(argv[2], "wb");
- if (output_file == NULL) {
- printf("Error opening output file.\n");
- fclose(input_file);
- return 1;
- }
- // Copy the contents from the input file to the output file
- int ch;
- while ((ch = fgetc(input_file)) != EOF) {
- fputc(ch, output_file);
- }
- // Close the files
- fclose(input_file);
- fclose(output_file);
- printf("File copied successfully.\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment