C structures and BIN file

K

karthikeyarajan

I have a "complicated" structure, a structure which in turn contains
many structures at different levels. There are "Count" fields inside
the structure to indicate the number of entries of a structure that
follows.

There are many instances of the "Outermost" structure populated in a
BIN file.

I need to parse the BIN file and populate the C structure. Is there
any utility or easier way to perform the same???

I have different sets of BIN file to be populated into different types
of structures.
Programming for each conversion is a time-consuming task (also error-
prone if we are not careful).

Please let me know a generic way for populating C structures from a
BIN file.

Thanks in Advance,
Itzme.
 
G

Gordon Burditt

I have a "complicated" structure, a structure which in turn contains
many structures at different levels. There are "Count" fields inside
the structure to indicate the number of entries of a structure that
follows.

There are many instances of the "Outermost" structure populated in a
BIN file.

If there are many instances of the outermost structure in a BIN file,
and *nothing else*, then you should be able to just fread() the outermost
structure in a loop, or even all of them at once into a sufficiently
large array.

If, however, you wrote this structure on an element-by-element basis
so it's not an actual image of the outermost structure, this won't work.
I need to parse the BIN file and populate the C structure. Is there
any utility or easier way to perform the same???

Since you haven't indicated in any detail what it's supposed to
*DO*, and the code is undoubtedly going to be heavily laced with
names and types of structure elements which you didn't give us,
that's going to be impossible.

You might look at Sun XDR where there's a routine for each type
that mostly calls a routine for its constituent types, until you
get down to the routines for the basic types which are provided.
But you've already GOT the BIN files in their own unique format,
don't you?
I have different sets of BIN file to be populated into different types
of structures.

You not only have different structures but different TYPES of structures
also?
Programming for each conversion is a time-consuming task (also error-
prone if we are not careful).

Please let me know a generic way for populating C structures from a
BIN file.

(a) graduate students.
(b) illegal aliens.
(c) outsourcing.
 
W

Wade Ward

Jack Klein is relevant here.

--
-- --
-- I'm using a bst to kill bugs today. 32 kills so far. That is an
authentic task.

During sorting, the most important technique is pre-selection, the
neceassayrry method for sorters who last more than 2 weeks at ups. Sara was
the best before I walked into the building. King Rooster.

abrasions: 2^(2+2^0)

nasty twisties
where they take steel
and crush your flesh against your bone
as they torque: 2^1

penetrations: 2^-(2 + 2 ......)

satisfaction of what happens
when thunderfist arrives 2^(2 + 2 ...)

n s ? foot / hand

e w ? hand \ foot

No survivors for n, e> 0. La cooka rach tja.
--
-- --
--
Wade Ward

"In any given barnyard, there can be only one rooster."
Wade Ward
"I put my pants on like any other 6: between four and a dozen failures."
{~._.~} The Naked Picture Poster from Down Under
`( Y )`
Gordon Burditt said:
If there are many instances of the outermost structure in a BIN file,
and *nothing else*, then you should be able to just fread() the outermost
structure in a loop, or even all of them at once into a sufficiently
large array.

If, however, you wrote this structure on an element-by-element basis
so it's not an actual image of the outermost structure, this won't work.


Since you haven't indicated in any detail what it's supposed to
*DO*, and the code is undoubtedly going to be heavily laced with
names and types of structure elements which you didn't give us,
that's going to be impossible.

You might look at Sun XDR where there's a routine for each type
that mostly calls a routine for its constituent types, until you
get down to the routines for the basic types which are provided.
But you've already GOT the BIN files in their own unique format,
don't you?


You not only have different structures but different TYPES of structures
also?


(a) graduate students.
(b) illegal aliens.
(c) outsourcing.
funny. mpj
 
B

Barry Schwarz

I have a "complicated" structure, a structure which in turn contains
many structures at different levels. There are "Count" fields inside
the structure to indicate the number of entries of a structure that
follows.

Every structure has a fixed size. C structures do not support members
which repeat a variable number of times. Every member of the
structure occurs within the structure exactly once. If the member is
an array, the number of elements in the array is also fixed. Your
Count field could tell you how many elements of an array member are
actually populated (contain data) but each element of the array exists
within the array and the array exists exactly once within the
structure.

If the structure member is a pointer, then it can point to the first
element of an array that is dynamically sized but that is not what you
describe.
There are many instances of the "Outermost" structure populated in a
BIN file.

I need to parse the BIN file and populate the C structure. Is there
any utility or easier way to perform the same???

Since the file is binary, you need to be absolutely certain that the
structure in your program exactly matches the layout of the structure
in the file. You also need the binary representation of each numeric
quantity (int, float, double, etc) in the file to match the
representation your system uses.
I have different sets of BIN file to be populated into different types
of structures.
Programming for each conversion is a time-consuming task (also error-
prone if we are not careful).

Please let me know a generic way for populating C structures from a
BIN file.

If the entire outer structure was written with a single fwrite and all
the layouts match up, you can read it with a single fread.

A couple of specific examples would probably make things a lot
clearer.


Remove del for email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,116
Latest member
LeanneD317
Top