-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram5.c
More file actions
38 lines (36 loc) · 929 Bytes
/
Program5.c
File metadata and controls
38 lines (36 loc) · 929 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
#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
#include <errno.h>
#include<string.h>
#define DATA_SIZE 1000
void copyfun(){
char ch, source_file[20], target_file[20];
FILE *source, *target;
printf("Enter name of file to copy\n");
scanf("%[^\n]%*c",source_file);
source = fopen(source_file, "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
printf("Enter name of target file\n");
scanf("%[^\n]%*c",target_file);
target = fopen(target_file, "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
}
int main()
{
copyfun();
}