-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicateFile.cpp
More file actions
47 lines (39 loc) · 917 Bytes
/
duplicateFile.cpp
File metadata and controls
47 lines (39 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <windows.h>
void duplicateFile()
{
char ch, source_file[20], target_file[20];
FILE *source, *target;
system ("cls");
backErrorSource:
printf("Enter name of file to copy\n");
scanf("%s", source_file);
source = fopen(source_file, "r");
if (source == NULL)
{
printf("\nError opening file\n");
goto backErrorSource;
}
backError:
printf("Enter name of target file\n");
scanf("%s", target_file);
target = fopen(target_file, "w");
if (target == NULL)
{
fclose(source);
printf("\nError opening file\n");
goto backError;
}
while ((ch = fgetc(source)) != EOF){
fputc(ch, target);
}
printf("File copied successfully.\n");
printf("Press any key to continue...");
getch();
fclose(source);
fclose(target);
system("cls");
}