-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24_file_copy.c
More file actions
58 lines (51 loc) · 1.13 KB
/
Copy path24_file_copy.c
File metadata and controls
58 lines (51 loc) · 1.13 KB
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
48
49
50
51
52
53
54
55
56
57
58
/***************************************************************************************
NAME : Karthikeyan.V
DATE : 8.08.2021
DESCRIPTION : Implement a my_cp() function
OUTPUT ./a.out file1.txt file2.txt
DATA SUCCESSFULLY COPIED
./a.out file1.txt
ERROR : DESTINATION FILE MISSING
./a.out file.txt file.txt
ERROR : NO SUCH A FILE
/a.out
ERROR : FILENAMES NOT PASSED
***************************************************************************************/
#include<stdio.h>
void myfunc_copy(FILE *, FILE *);
int main(int argc, char **argv)
{
FILE *fptr1, *fptr2;
if(argc == 3)
{
fptr1 = fopen(argv[1], "r");
if(fptr1 == NULL)
{
printf("ERROR : NO SUCH A FILE\n");
return 0;
}
else
{
fptr2 = fopen(argv[2], "w");
myfunc_copy(fptr2, fptr1);
}
}
else if(argc == 1)
printf("ERROR : FILENAMES NOT PASSED\n");
else if(argc == 2)
printf("ERROR : DESTINATION FILE MISSING\n");
return 0;
}
void myfunc_copy(FILE *dest, FILE *src)
{
char ch;
while(ch = fgetc(src))
{
if(feof(src)) //proceed till end of file
{
printf("DATA SUCCESSFULLY COPIED\n");
break;
}
fputc(ch, dest);
}
}