Re: Writing a character to the beginning of the same file



In article <1114660481.571702.267690@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
mshyamrao@xxxxxxxxx says...
> So what is the solution to write a character to the beginning of the
> file and not affect the existing content.

Homework notwithstanding consider the following:


If it sufficiently small to store in memory
open the file
read the whole file into dynamic storage
close the file
else
copy the file (or rename it) somewhere else

open the file for writing positioned at the beginning of the file
write the single new character

Depending on the conditional above

either write the contents straight from dynamic storage into the
file just like the last character
or
read from the copy/renamed version of the original file and
write into the new one

close the file
exit

If that doesn't get you anywhere, drop the class or hire a tutor.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
.



Relevant Pages

  • Re: Writing a character to the beginning of the same file
    ... > write the single new character ... > Depending on the conditional above ... > either write the contents straight from dynamic storage into the ... > Randy Howard ...
    (comp.programming)
  • Re: array of pointers to char in functions
    ... Since there's a scent of homework in the air, ... > int i; ... character canary in the inner loop? ... parentheses *are* required when `sizeof' is ...
    (comp.lang.c)
  • Re: Efficency
    ... language or do your homework, but asking questions (even simple ones, ... get character from buffer ... check whether buffer needs to be refilled ... and leave any other optimization until after it's shown to be needed. ...
    (comp.lang.c)
  • Re: Odd! Excel changes my letter character. Why?
    ... I'm doing some homework for a class. ... I have a workbook set up with ... worksheets for each chapter's homework answers. ... any other "word" with i and another letter character or number character ...
    (microsoft.public.excel.misc)
  • Re: Odd! Excel changes my letter character. Why?
    ... I'm doing some homework for a class. ... any other "word" with i and another letter character or number character ... the number keys, or the brackets next to the p key, or the arrows, ...
    (microsoft.public.excel.misc)