-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy.c
executable file
·44 lines (37 loc) · 1004 Bytes
/
Copy.c
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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef uint8_t BYTE;
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("Please pass the file name to be copied and the destination of copying only, as the commands ");
return 1;
}
// File to be copied
FILE *originalFile = fopen(argv[1], "r");
if (originalFile == NULL)
{
printf("Could not open file %s.\n", argv[1]);
return 1;
}
// Location of copying
FILE *destinationFile = fopen(argv[2], "w");
if (destinationFile == NULL)
{
fclose(originalFile);
printf("Could not create file %s.\n", argv[2]);
return 1;
}
//Copying 1 Byte at a time
BYTE buffer;
while (fread(&buffer, sizeof(BYTE), 1, originalFile))
{
fwrite(&buffer, sizeof(BYTE), 1, destinationFile);
}
// Close files
fclose(originalFile);
fclose(destinationFile);
return 0;
}