473,396 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

looking for sample code: writing file content to binary

CJ
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 character has been
found, a modification printf message will print to screen.

Any ideas? Or good C-link with sample code you could direct me to?

Thanks heaps.
Nov 14 '05 #1
2 1410
ca********@hotmail.com (CJ) wrote:
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


Binary files don't have lines, by definition.
comparison on characters. When the first different character has been
found, a modification printf message will print to screen.

Any ideas? Or good C-link with sample code you could direct me to?


1. Open both files in "rb" mode.
2. In a loop, read one character at a time from each file.
3. Emit a message if the two characters differ.

If you run into problems implementing this in C, please report back,
showing your actual code.

HTH
Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #2
CJ <ca********@hotmail.com> wrote:
: 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 character has been
: found, a modification printf message will print to screen.

Part of what it means to be a "binary file" is that there are no
"lines", i.e. there is no character which is interpreted as an end
of line character. So you can't do a "line by line comparison".
You can, however, do a byte by byte comparison. Look at your compiler's
documentation for fgetc() and getc() to read bytes from a file.

Good Luck,

Paul
--
Paul D. Boyle
bo***@laue.chem.ncsu.edu
North Carolina State University
http://www.xray.ncsu.edu
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
1
by: Bangalore | last post by:
Hi all, I was trying out the following program, I want to copy the content of struct x variable to file. Here using write of fwrite(used with FILE *fl) I am not able to write integer part to...
11
by: Dale | last post by:
How to recognize whether file has XML format or not? Here is the code segment: XmlDocument* pDomDocument = new XmlDocument(); try { pDomDocument->Load(strFileName ) ; } catch(Exception* e) {
5
by: Gregory Silvano | last post by:
I have reproduced this problem on several machines (all different configs) and don't see anything wrong with the code. The code below (or very similar) is from Microsoft (help files, newsgroup...
3
by: A.M | last post by:
Hi, I want to publish some pdf file in my asp.net application but I don't wnat to publish them directly. I would like to use an intermidiate aspx file like http://domain.com/GetFile.aspx?ID=123...
1
by: Ryan | last post by:
can i create a link that doesnt open a browser window... a link that executes the aspx.vb code first (code that creates a file) and transfers to an opening of a dynamically created (vcs outlook)...
0
by: Smoke | last post by:
Im developing a custom app that has to read a file generated from other program, actually, the file is pretty much a mail message, which contains the subject, to, from, body, etc etc and also the...
5
by: Otto Wyss | last post by:
I've now been looking for a week for a simple but useful sample on how to get a list of entries (persons) via an XMLHttpRequest using Json/PHP on the server. So far I've found about a thousend...
6
by: WT | last post by:
Hello, Using url rewritting and ajax.net, I tried to circumvent some potential problems with postback url using a code from a sample given by Scott. The idea is to use a control Adapter on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.