![]() |
|
#1
|
|||
|
|||
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 CPP / C++ / C Code:
Last edited by dsmith : 06-Mar-2004 at 07:44.
Reason: Please use [c] & [/c] to enclose C code for highlighting
|
|
#2
|
||||
|
||||
|
Hi Janet. Welcome to GIDForums. I think that your program is outputing EOF. If I remember correctly feof will only be true if the file pointer is sitting on feof. So if you look at your while loop:
CPP / C++ / C Code:
Your program is getting the end of file, storing it into inChar, writing it out and then checking for the end of file. I would fix this by adding a quick if statement like so: CPP / C++ / C Code:
See if that fixes it. Cheers, d |
|
#3
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
Also, do NOT use gets(). It has a tendancy to make your program explode. Change the gets(inFilename) to CPP / C++ / C Code:
The problem with gets() is if you enter ABCDEFGHIJKLMNOPQRSTUVWXYZ.FILETYPE as the filename, the 1st 12 characters will be loaded into the variable, the characters after those 12 get loaded into the bytes following -- destroying other variable contents and possibly writing to space not available to the program. The program then crashes. So never use gets(). It's not worth the headaches. |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Mozilla Thunderbird | dsmith | Computer Software Forum - Linux | 9 | 01-Mar-2005 12:56 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
| [script] Handling Error 404 | JdS | PHP Code Library | 0 | 19-Nov-2003 09:22 |
| [script] E-mail webmaster error page | BobbyDouglas | PHP Code Library | 0 | 19-Aug-2003 21:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The