Doubt in file handling

H

Harry

Dear all,

I am having an integer array of size 176x144.I need to copy the first
256 bytes from this array to a file,then the next 256 and so
on...which function i can use.I am using Visual C++ compiler(C
language i am using).I tried out fwrite.But the values in the text
file where in ASCII.I want themto be in decimal or hexadecimal.....how
can i do it?

thanks in advance
 
C

Chris Dollin

Harry said:
I am having an integer array of size 176x144.I need to copy the first
256 bytes from this array to a file,then the next 256 and so
on...

If you have an /integer/ array (do you mean an /int/ array?), why are
you worried about /bytes/?

And if your array is 176x144, why /256/ bytes?
which function i can use.I am using Visual C++ compiler(C
language i am using).I tried out fwrite.But the values in the text
file where in ASCII.I want themto be in decimal or hexadecimal.....how
can i do it?

If you use `fwrite`, you will write out the raw bytes of the array,
and if you look at them with a text editor (or type them to the screen),
what you will see will be character garbage. If what you /want/ is the
decimal representation of the integer values, I'd suggest using `fprintf`,
with a format string like " %d" ("a space then the decimal representation
of the next int argument").

And if you have a problem doing that, post here /showing your exact code/
(after making it small and simple and to the point), because if we can't
see it, we can't debug it [1].

[1] Usually.
 
H

Harry

Harry said:
I am having an integer array of size 176x144.I need to copy the first
256 bytes from this array to a file,then the next 256 and so
on...

If you have an /integer/ array (do you mean an /int/ array?), why are
you worried about /bytes/?

And if your array is 176x144, why /256/ bytes?
which function i can use.I am using Visual C++ compiler(C
language i am using).I tried out fwrite.But the values in the text
file where in ASCII.I want themto be in decimal or hexadecimal.....how
can i do it?

If you use `fwrite`, you will write out the raw bytes of the array,
and if you look at them with a text editor (or type them to the screen),
what you will see will be character garbage. If what you /want/ is the
decimal representation of the integer values, I'd suggest using `fprintf`,
with a format string like " %d" ("a space then the decimal representation
of the next int argument").

And if you have a problem doing that, post here /showing your exact code/
(after making it small and simple and to the point), because if we can't
see it, we can't debug it [1].

[1] Usually.


ya i got the problem solved as u said....i used fprintf.thanks a lot
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top