how to read file content into a structure

First of all, your file should be written in binary which contains nothing but the objects of your c structure.

Here's a breakdown of what you should do:
1. Open the file in binary format and read to the end of the file. Make sure the size is correct (correct size should be a multiple of your c structure's size)
2. If the structure is correct, allocate memory to the pointer using malloc()
3. use fread() to read the whole chunk to the pointer

You're now ready to access your c structure from the pointer.

First of all, your file should be written in binary which contains nothing but the objects of your c structure.

LOL WUT?

come on man, if you're going help, at least make sense. I think i know what you mean, but i doubt any beginning C coder does.


Here's a breakdown of what you should do ... <snip>

this makes way too many assumptions.

ramakrishna, you need to tell us more information about what your structure and your file looks like and what kind of assumptions can be made about the size, order, and relative placement of elements.

In other words, what are you trying to do, exactly?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.