wrote:
> Hi all,
>
> I have a file in which I have several blank spaces. I would like to
> remove all these blank spaces from the file.
> What is the most efficient way of doing it using minimal storage.
> Other than copying to some other file is
> there any other good way of doing it.
Copying (and omitting the blanks) is probably the most
efficient.
If you insist on not copying the file, I think you're
out of luck. The result will be shorter than the original,
and C has no way to shorten an existing file (other than to
length zero). You *could* overwrite the blanks with "ignore
me" bytes, or squeeze them out and write "ignore me" bytes
at the end, but that doesn't seem any better than just ignoring
the blanks in the first place.
If you're willing to go beyond C's I/O facilities you
might find platform-specific ways to shorten a file. If so,
you could "slide" bytes toward the beginning of the file to
"squeeze out" the blanks, and then use the shortening method
to chop off the leftover junk at the end. I expect this would
be far less efficient than the copy-with-filter approach.
--
Eric Sosman
lid