Re: read from file question

"osmium" <r124c4u102@xxxxxxxxxxx> writes:
"Arquitecto" wrote:
I have a question about a file operation i want to do . I have a data
file lets say X bytes . I want to read the file and delete a byte
every 2nd byte .
I would do it like this. Create an output buffer and put the
desired data in it using the indexing operations. Then write the
output buffer to a new file. When you are done, delete the original
file and rename the new file to have the name of the old file.

That implies storing half the contents of the input file in memory,
without knowing how big the input file is. Allocating memory for this
can be tricky; realloc should do it *if* it's possible at all.

But it's not necessary. As you're reading the input file, write every
other character to the output file. When you're done, close the input
and output files and rename the output file. (And do error checking.)

Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <>
San Diego Supercomputer Center <*> <>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"