Re: read/write at the same time
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 1 Nov 2008 14:05:57 +0100
<dolatabadi.amir@xxxxxxxxx> wrote in message
news:e405e478-f8d0-4be3-97db-f9b67630280b@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I want to write a program to create prime numbers. As part of it, I
must create a file, then write prime numbers in it and also read from
to it in order to create other primes. I used a text file, but can
not have access to it simulataneously for read and write access. Reset
procedure allows me reading from it and rewrite allows me only writing
in it. How I can have permission to do both at the same time?
By not using a text file. The help file says as much: "When opening a
text file, it will be read-only" (or words to that effect). Otherwise,
it won't.
Text files have unusual semantics - they are considered to consist of
lines, separated by end-of-line sequences, and the lines are _variable_
_length_. That means that when you want to shorten a line near the
beginning, you have to move up all the text after it, or a spurious
line will be inserted. As opposed to Pascal's other type of file, the
sequence of fixed-length records, where you can change one record
without affecting all the others (but obviously not remove it, either).
Both types of files are relics from ancient times anyway.
You have the advantage that you know _where_ you will be reading and
writing. I think it should be possible to split the single file into
'pages', with a page per file, in such a manner that you only need
either read or write access to any page at one time.
Is this an exercise with given restrictions? How many primes will you
generate? How are you representing your numbers? We can tell you more
if you tell us more.
Groetjes,
Maarten Wiltink
.
- Follow-Ups:
- Re: read/write at the same time
- From: dolatabadi . amir
- Re: read/write at the same time
- From: Dr J R Stockton
- Re: read/write at the same time
- References:
- read/write at the same time
- From: dolatabadi . amir
- read/write at the same time
- Prev by Date: read/write at the same time
- Next by Date: Re: read/write at the same time
- Previous by thread: read/write at the same time
- Next by thread: Re: read/write at the same time
- Index(es):
Relevant Pages
|