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 <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Help is needed to compile C program using Visual Studie 2005
    ... the pdb file that was used when this precompiled header was created, ... an output file whose name has the following format: ... The length of input file paths and name must be less than 256; ... while(i < DefinedVariableArrayIndex) { ...
    (microsoft.public.vc.language)
  • Re: Need advice on File I/O
    ... open the input file and open an output file, ... you would still have the input file unchanged. ... On all currently supported operating systems, ...
    (comp.soft-sys.matlab)
  • Re: Difficult text file to parse.
    ... > records are which there are only two, look at the output file below to ... I want to show the delimiters even if ... > My sample Input file: ... [sample input and output files with long fields snipped] ...
    (comp.lang.perl.misc)