View Single Post
  #1 (permalink)  
Old March 6th, 2004, 04:08 AM
Janet Janet is offline
Registered User
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default File copy routine error!

I am writing a program that can duplicate a binary file.
However, the new file will hav extra byte (0xFF) at the end of new file. For example, original file (123.bin) contains 11 Bytes, the generated file (abc.bin) is 12 Bytes, because an extra 0xFF appended at the end of it. How to get rid of it?

123.bin: 6162631198F5BB77660061
abc.bin: 6162631198F5BB77660061FF

*******source code***************
#include <stdio.h>
#include <stdlib.h>

FILE *inFp;
FILE *outFp;

void main() {
    char inFilename[12];
    char outFilename[12];

    int inChar;

    printf("What is the name of the file you want to back up? ");

    printf("What is the name of the file ");
    printf("you want to copy %s to? ", inFilename);

    if ((inFp = fopen(inFilename, "rb")) ==NULL) {
        printf("\n\n*** %s does not exist ***\n", inFilename);

    if ((outFp = fopen(outFilename, "wb")) == NULL) {
        printf("\n\n*** Error opening %s ***\n", outFilename);


    while (!feof(inFp)) {
        inChar = getc(inFp);
        putc(inChar, outFp);

    printf("\nThe files are copied.\n");


Reply With Quote