fp.c 896 Bytes
#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;
}