1. compare
- Posted by Greg Phillips <i.shoot at REDNECKS.COM> Dec 15, 1998
- 383 views
- Last edited Dec 16, 1998
Okay, a quick question.... I decided to write a quick program that'd compare a file, byte by byte, and tell you if they're the same or different. My program opened two files in read only mode, got the data from the file, compare()'d it, and returned a "Files are the same" or "Files are different" string, which worked great, as long as the files were fairly small....if the files were 10k, I could change one character, and it would detect the difference, but a 50k file, and I'd have to change a few characters for it to tell the difference. The bigger the file, the more char's had to be changed to return a false value.... hrm... damnit, all I wanted was something like the old dos compare program....*sigh* oh well, guess I'll have to get those old dos 5 disks out. I really hope they aren't on 5 1/4. Anyways, this is kinda bugging me, and I'd really like to feel that familiar pride of writing something myself, and actually using it for something, too =) thanks, Greg -- Greg Phillips i.shoot at rednecks.com http://euphoria.server101.com -- Useless fact of the day: Sex burns 360 calories per hour
2. Re: compare
- Posted by Robert Craig <rds at EMAIL.MSN.COM> Dec 16, 1998
- 374 views
Greg Phillips writes: > I decided to write a quick program that'd > compare a file, byte by byte, and tell you if they're the same or > different. My program opened two files in read only mode, got the data > from the file, compare()'d it, and returned a "Files are the same" or > "Files are different" string, which worked great, as long as the files > were fairly small....if the files were 10k, I could change one > character, and it would detect the difference, but a 50k file, and I'd > have to change a few characters for it to tell the difference. It sounds like your program opens the files with "r" mode (text), when it should really use "rb" mode (binary). DOS does funny things when you open a file in text mode and the file has certain non-text characters in it. For example, when the ASCII code 26 (control-Z) is encountered, DOS will report "end of file", even when there are lots of characters remaining in the file. Maybe you compared two files that were the same up to 10K, and then both of them had 26 - they'd appear to be identical, even though they differ at some point after 10K. Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/
3. Re: compare
- Posted by Rolf Schroeder <schroeder at DESY.DE> Dec 16, 1998
- 361 views
Greg Phillips wrote: > > Okay, a quick question.... I decided to write a quick program that'd > compare a file, byte by byte, and tell you if they're the same or > different. My program opened two files in read only mode, got the data > from the file, compare()'d it, and returned a "Files are the same" or > "Files are different" string, which worked great, as long as the files > were fairly small....if the files were 10k, I could change one > character, and it would detect the difference, but a 50k file, and I'd > have to change a few characters for it to tell the difference. The > bigger the file, the more char's had to be changed to return a false > value.... hrm... damnit, all I wanted was something like the old dos > compare program....*sigh* oh well, guess I'll have to get those old dos > 5 disks out. I really hope they aren't on 5 1/4. > > Anyways, this is kinda bugging me, and I'd really like to feel that > familiar pride of writing something myself, and actually using it for > something, too =) > > thanks, > Greg > > -- > Greg Phillips > i.shoot at rednecks.com > http://euphoria.server101.com > -- > > Useless fact of the day: > > Sex burns 360 calories per hour Greg, why do you use compare() instead of getc()? getc() is fast, and you are able to compare files as large as they may be (not limited by memory). If you want to testify that files are identical (name and content) look at my DIRCMP.EX which you may find in the 'user contributions'. Have a nice day, Rolf the length of the files