fp.c
896 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
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
FILE *forg, *fnew;
int offset, count, i;
if (argc != 5) {
printf("\n Usage: fp original_file offset count new_file\n");
return -1;
}
if ((forg = fopen(argv[1], "rb")) == NULL) {
printf("Cannot open file %s to read \n", argv[1]);
return -1;
}
if ((fnew = fopen(argv[4], "wb")) == NULL) {
printf("Cannot open file %s to write \n", argv[1]);
fclose(forg);
return -1;
}
offset = atoi(argv[2]);
count = atoi(argv[3]);
printf("Copy %s from %d to %d ==> %s \n",
argv[1], offset, offset+count, argv[4]);
fseek(forg, offset, SEEK_SET);
for (i=0; i<count; i++) {
if (!feof(forg)) fputc(fgetc(forg), fnew);
else fputc(0, fnew);
}
fclose(forg);
fclose(fnew);
return 0;
}