i want help on FILE IO

M

meet2amit_p

hi
i hv stored 32 HEX numbers in a file and i want to load it into int
arr[32].
i hv tried so but i cant.
how can i do it ?
Please help...!
 
I

Ico

hi
i hv stored 32 HEX numbers in a file and i want to load it into int
arr[32].
i hv tried so but i cant.
how can i do it ?

Show us the code of what you tried so far so we can give you some tips
and comments on what is wrong with your program.
 
R

Richard Heathfield

(e-mail address removed) said:
hi
i hv stored 32 HEX numbers in a file and i want to load it into int
arr[32].

There is no such thing as a hex number. Presumably you mean you've stored
the hexadecimal representations of 32 numbers. And now you want to convert
them back into numbers. That's easy enough. Just open the file, read in
each representation in turn, and pass it to strtoul, specifying 16 as the
third argument (the base specifier). Store the result in arr.
 
M

Malcolm

Richard Heathfield said:
(e-mail address removed) said:
hi
i hv stored 32 HEX numbers in a file and i want to load it into int
arr[32].

There is no such thing as a hex number.
But there are numbers with hexes on them. Like these.
Presumably you mean you've stored
the hexadecimal representations of 32 numbers. And now you want to convert
them back into numbers. That's easy enough. Just open the file, read in
each representation in turn, and pass it to strtoul, specifying 16 as the
third argument (the base specifier). Store the result in arr.

I suspect that the numbers have been stored in binary format. They could be
16 or 32 bit, little or big endian. So it is bit of a messy job to load them
portably, but it can be done.

To the OP, give us a hex (not hexed) dump of the file, with a list of the
values the numbers should take if you have them, an idea of the range if you
don;t have the numbers.
 

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

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,369
Latest member
Carmen32T6

Latest Threads

Top