473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

File comparison in c++

105 New Member
Hi all,

I have to perform binary comparison of the generated files each time I build my program.

For example in my first build I generate a header file and data file and store them in reference directory. Next time when I build the program again I will be generating the same files and I have to compare the ones in my reference directory if they are same. I have seen different utility programs that performs file comparison on the command line. But I have to include this comparison in my program and generate a file if there are any differences in the files.

Could anyone please help me with this?

P.S: I am working on Visual 2005 and it is console application.

Thanks.
May 4 '07 #1
10 3636
Savage
1,764 Recognized Expert Top Contributor
Hi all,

I have to perform binary comparison of the generated files each time I build my program.

For example in my first build I generate a header file and data file and store them in reference directory. Next time when I build the program again I will be generating the same files and I have to compare the ones in my reference directory if they are same. I have seen different utility programs that performs file comparison on the command line. But I have to include this comparison in my program and generate a file if there are any differences in the files.

Could anyone please help me with this?

P.S: I am working on Visual 2005 and it is console application.

Thanks.
And how is ur programm building files?

Is it line by line or char by char?

Savage
May 4 '07 #2
mickey22
105 New Member
My program generates for example the header file through a system commandand it is like text file with characters and numbers.On the other hand a data file is created containing ASCII characters.Each time I build my program I run these system commands and new version of files are created.
I guess answer to your question, my program is building line by line.
I did not exactly understand the question.

Please let me know if you need more information.

Thanks.
May 4 '07 #3
Savage
1,764 Recognized Expert Top Contributor
My program generates for example the header file through a system commandand it is like text file with characters and numbers.On the other hand a data file is created containing ASCII characters.Each time I build my program I run these system commands and new version of files are created.
I guess answer to your question, my program is building line by line.
I did not exactly understand the question.

Please let me know if you need more information.

Thanks.
Ok so it's line by line which means that u can create a simple while loop which will loop until eof is reached and files are not updated.In loop body u must test those lines for equlaity and if new line is different from line in file replace it in ur file.

Savage
May 4 '07 #4
AdrianH
1,251 Recognized Expert Top Contributor
Hi all,

I have to perform binary comparison of the generated files each time I build my program.

For example in my first build I generate a header file and data file and store them in reference directory. Next time when I build the program again I will be generating the same files and I have to compare the ones in my reference directory if they are same. I have seen different utility programs that performs file comparison on the command line. But I have to include this comparison in my program and generate a file if there are any differences in the files.

Could anyone please help me with this?

P.S: I am working on Visual 2005 and it is console application.

Thanks.
Why do you have to do a binary comparison exactly? What do you hope to achieve?

I'm asking this because doing a binary comparison may not be the best most efficient way of doing what you are attempting to do. It might be, but I am just giving you some other option.


Adrian
May 4 '07 #5
mickey22
105 New Member
I have to do this for debugging purposes.In case if there are any differeneces between the files when comparison is done, it means that code has been updated somewhere.

I am stiull not clear how to start this.Could you please explain me more clear how to get started.Just have to make it simple comparison.

Please let me know if any questions.

Thanks.
May 7 '07 #6
Savage
1,764 Recognized Expert Top Contributor
I have to do this for debugging purposes.In case if there are any differeneces between the files when comparison is done, it means that code has been updated somewhere.

I am stiull not clear how to start this.Could you please explain me more clear how to get started.Just have to make it simple comparison.

Please let me know if any questions.

Thanks.
What exactly confuse u?Do u know to use functions for data reading?

Savage
May 7 '07 #7
mickey22
105 New Member
Just wanted to make clear what u said is if it is large data file with ASCII char's I need to parse through each value in the file and check for equality?

I also need some help with the functions.Could you please tell me what kind of functions I can use?

Thanks
May 7 '07 #8
Savage
1,764 Recognized Expert Top Contributor
Just wanted to make clear what u said is if it is large data file with ASCII char's I need to parse through each value in the file and check for equality?

I also need some help with the functions.Could you please tell me what kind of functions I can use?

Thanks
That's the best way to be sure that files (don't)match.

Use fgets to read in a single line,compare that line with line that u are just about to output in same file using strcmp,if there is any differance output the new line,otherway read in another line and reapet same process until EOF.

Savage
May 7 '07 #9
AdrianH
1,251 Recognized Expert Top Contributor
I have to do this for debugging purposes.In case if there are any differeneces between the files when comparison is done, it means that code has been updated somewhere.

I am stiull not clear how to start this.Could you please explain me more clear how to get started.Just have to make it simple comparison.

Please let me know if any questions.

Thanks.
But why reinvent the wheel? There are a bunch of utilities that do binary comparisons. Windoze uses FC, Unicies use diff.

Further, you could put a static char array at the beginning of each source and assign it to "Compiled: " __DATE__ __TIME__. It would make the object binary slightly bigger, but not only would you be able to compare the files faster (it should appear near the beginning of the object file if you make it appear at the beginning of the source file, allowing you to bail sooner when you find it), it would also tell you when it was modified.

An even faster method under Windozs is to use the archive file bit. Set all the files as archived by clearing the archive bit (use attrib /S -A * from the correct directory) and do a recompile. Any files that are modified will have their archive bits reset. (use attrib /S to find these or make your own utility).

More generically under Unix (or using Cygwin or MinGW under Windoze), create a new file (use touch to create it) and then do a recompile. From there you would do a time stamp comparison between the file you created using touch and the files in the compile directory (use test to do this comparison). All modified ones would have a date stamp that is newer than the file you created (unless your system clock is going backwards ;) :D)

These last two methods are much faster than comparing the files against each other because you are only checking the file attributes, not the entire file. You also don't have to make a copy of the original directory (unless you want to do that for backing up).

What OS, compiler and IDE are you using?


Adrian
May 7 '07 #10
mickey22
105 New Member
I am using Windows OS, INTEL C++ compiler, Visual c++ 2005
May 7 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bill W. | last post by:
I'm teaching myself VB6. As a first project, I've decided to work on a Window's version of the Unix command, "diff" -- with a few twists. But being unfamiliar with VB, I am unsure as to how to...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
2
by: CJ | last post by:
I've got following: > file_a content needs to be compared with file_b content. I want to write content in binary form, then run a line by line comparison on characters. When the first different...
8
by: Smith | last post by:
I know this question is not much related to this news group. Is there any free utility on the web which campares files in two folders for changes. I wanted to compare two set of .ASPX files?...
1
by: sympatico | last post by:
Hi, I am trying to compare 2 images to check if they are exactly identical (in terms of data), I thought this would be quicker than analysing pixels of the images. I have found lots of examples...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
7
by: Alan | last post by:
Hi. I have programmed in C++ before, but I`m a couple of years out of practice. I am seeking some advice on getting started on a quickie project. . . . I have to read a 54MB text file and do a...
24
by: Johnny Jörgensen | last post by:
I'm wondering (and hoping that somebody will be able to answer this): If I calculate the hash value of files (either MD5 or SHA1), can I then be sure that: 1) Two files with the same hash...
1
risk32
by: risk32 | last post by:
Hello. I'm trying to open a file for comparison to two (2) input box text values. ie: txtPassword.text + ";" + txtUsername.text must equal whats in a line in the UNPW (username password) text file...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.