PROBLEM READING/WRITING FILE __SIMULTANEOUSLY__! 
Author Message
 PROBLEM READING/WRITING FILE __SIMULTANEOUSLY__!

        I'm just beginning to grasp the C language, so please
bear with me on this problem; I want to load a file, locate a
special character (a relatively unused ASCII character - such
as pre-32 characters - I am aware this sacrifices portability)
of which there will only be one in the document. I then want to
insert text at this point in the document.
        I can't do this by just opening a file for reading,
and then finding the character, because they I cannot replace
it with text because I haven't opened the file for writing. If
I then open the file for writing the position of the character
is then forgotten.
        What is the standard way to do this in 'C'? Please respond

        Many thanks,
                        Andrew.

--

 * "Did I request thee, Maker, from my clay, to mould me Man?*
 * Did I solicit thee, from Darkness to promote me?"         *



Fri, 19 Feb 1999 03:00:00 GMT  
 PROBLEM READING/WRITING FILE __SIMULTANEOUSLY__!

Quote:

>        I'm just beginning to grasp the C language, so please
>bear with me on this problem; I want to load a file, locate a
>special character (a relatively unused ASCII character - such
>as pre-32 characters - I am aware this sacrifices portability)
>of which there will only be one in the document. I then want to
>insert text at this point in the document.

While the wording of the FAQ called "How can I insert or delete
a line (or record) in the middle of a file?" does not fit your
problem exactly, the answer to that question certainly does.
A lot of file systems do not support such operations, and the
C programming language does not require such support. Your only
option beyond system specific magic is to copy the file up to
the desired point, insert your string, and append the rest of
the original file.

Kurt

--
| Kurt Watzka                             Phone : +49-89-2180-6254



Sat, 20 Feb 1999 03:00:00 GMT  
 PROBLEM READING/WRITING FILE __SIMULTANEOUSLY__!


Quote:


>>        I'm just beginning to grasp the C language, so please
>>bear with me on this problem; I want to load a file, locate a
>>special character (a relatively unused ASCII character - such
>>as pre-32 characters - I am aware this sacrifices portability)
>>of which there will only be one in the document. I then want to
>>insert text at this point in the document.

>While the wording of the FAQ called "How can I insert or delete
>a line (or record) in the middle of a file?" does not fit your
>problem exactly, the answer to that question certainly does.
>A lot of file systems do not support such operations, and the
>C programming language does not require such support. Your only
>option beyond system specific magic is to copy the file up to
>the desired point, insert your string, and append the rest of
>the original file.

However, if the problem isn't to *insert*, but rather to
*overwrite* starting at the noted point, then opening
the file with a "+" mode (r+/rb+/w+/wb+) should suffice.
Remember to do a fseek(fp, 0L, SEEK_CUR) (or another similar
command as mentioned in the standard, which is at my
other office right now or I'd quote it) between the read
and the write.

                --Ken Pizzini



Tue, 23 Feb 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. dangers of writing and reading a file simultaneously?

2. Write to 2 files simultaneously

3. Reading and simultaneously deleting from a file

4. Problem opening a file for read while it is open for write

5. File Read/Write Problem

6. File reading/writing problem

7. file reading/writing speed problem

8. problem reading from and writing to file - please help

9. problem reading/writing text file from disk

10. File read/write problems

11. Reading a file / Write what you read

12. Reading a pattern of string from text file and writing it to a new file

 

 
Powered by phpBB® Forum Software