I am reading the docs on fopen() and think I want to use the r+ option
so I can read in a file, make changes to the data, write the changes
back, overwriting the original data. I believe using flock() will lock
the file while I am doing this (is this so?) so no one else can access
it. The question I have is, in the docs it says it sets the file
pointer to the begining of the file for reading, but where is the
filepointer set to for writing, or does it over write the existing
information as soon as I write back to the file?
Any help, pointers, etc appreciated
Bill H 5 2479
Bill H wrote:
I believe using flock() will lock the file while I am doing this (is this
so?) so no one else can access it.
Nope - please re-read the PHP manual. flock() is an *optimistic* locking
solution.
The question I have is, in the docs it says it sets the file
pointer to the begining of the file for reading, but where is the
filepointer set to for writing, or does it over write the existing
information as soon as I write back to the file?
To the beginning in write mode, to the end in append mode. Please RTFM: http://php.net/fopen
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
On Sep 26, 8:54*am, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Bill H wrote:
I believe using flock() will lock the file while I am doing this (is this
so?) so no one else can access it.
Nope - please re-read the PHP manual. flock() is an *optimistic* locking
solution.
The question I have is, in the docs it says it sets the file
pointer to the begining of the file for reading, but where is the
filepointer set to for writing, or does it over write the existing
information as soon as I write back to the file?
To the beginning in write mode, to the end in append mode. Please RTFM:http://php.net/fopen
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
Ivan
I am asking about the "r+" mode, I understand the w+ and a+, but the r
+ is vague
The manual says: 'r+' Open for reading and writing; place the file
pointer at the beginning of the file. My question was - does this mean
that any writing starts at the begining of the file also and
overwrites existing data? Or is any data that is writen placed where
you left off reading?
Bill H
On 26 Sep, 15:54, Bill H <b...@ts1000.uswrote:
On Sep 26, 8:54*am, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Bill H wrote:
I believe using flock() will lock the file while I am doing this (is this
so?) so no one else can access it.
Nope - please re-read the PHP manual. flock() is an *optimistic* locking
solution.
The question I have is, in the docs it says it sets the file
pointer to the begining of the file for reading, but where is the
filepointer set to for writing, or does it over write the existing
information as soon as I write back to the file?
To the beginning in write mode, to the end in append mode. Please RTFM:http://php.net/fopen
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
Ivan
I am asking about the "r+" mode, I understand the w+ and a+, but the r
+ is vague
The manual says: 'r+' Open for reading and writing; place the file
pointer at the beginning of the file. My question was - does this mean
that any writing starts at the begining of the file also and
overwrites existing data? Or is any data that is writen placed where
you left off reading?
Why didn't you just try it?
Bill H schreef:
I am asking about the "r+" mode, I understand the w+ and a+, but the r
+ is vague
The manual says: 'r+' Open for reading and writing; place the file
pointer at the beginning of the file. My question was - does this mean
that any writing starts at the begining of the file also and
overwrites existing data? Or is any data that is writen placed where
you left off reading?
This means that the file is truncated (emptied) before writing. It also
implies that the result of the following is an empty file:
$fp = fopen('file', 'r+');
fclose($fp);
JW
Bill H wrote:
On Sep 26, 8:54 am, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>Bill H wrote:
>>I believe using flock() will lock the file while I am doing this (is this so?) so no one else can access it.
Nope - please re-read the PHP manual. flock() is an *optimistic* locking solution.
>>The question I have is, in the docs it says it sets the file pointer to the begining of the file for reading, but where is the filepointer set to for writing, or does it over write the existing information as soon as I write back to the file?
To the beginning in write mode, to the end in append mode. Please RTFM:http://php.net/fopen
-- ---------------------------------- Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
Un ordenador no es un televisor ni un microondas, es una herramienta compleja.
Ivan
I am asking about the "r+" mode, I understand the w+ and a+, but the r
+ is vague
The manual says: 'r+' Open for reading and writing; place the file
pointer at the beginning of the file. My question was - does this mean
that any writing starts at the begining of the file also and
overwrites existing data? Or is any data that is writen placed where
you left off reading?
Bill H
The file pointer is used for both the reading and writing position, data
you write will be placed where you left off reading. If you want to
overwrite it you will need to use fseek() to move the pointer back to
the start.
Jamie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Shaoyong Wang |
last post by:
Dear All,
I want to write a simple PHP code to verify whether a given list of
URLs is broken or not. The URLs given have various formats, for example,
http://www.afro.com/history/history.html...
|
by: Ming |
last post by:
When I use fopen on the URL:
fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r")
I would get the following error message:
-----------Error Message------------
Warning: fopen():...
|
by: David Buchan |
last post by:
Hi guys,
This may be a dumb question; I'm just getting into C language here.
I wrote a program to unpack a binary file and write out the contents to
a new file as a list of unsigned integers....
|
by: Longfellow |
last post by:
Newbie here...
My reading of the description of fopen() led me to expect that, with
mode as "w", it would create a file if it did not exist. Checked the
FAQ and did not see this question...
|
by: siliconwafer |
last post by:
Hi All,
here is one code:
int main() {
FILE*fp;
unsigned long a;
fp = fopen("my_file.txt","w+");
a = 24;
fprintf(fp,"%ld",a);
while(fscanf(fp,"%ld",&a) == 1) {
|
by: Mike |
last post by:
Hello,
Im doing this in php5, apache
Im not sure where the problem lies but I have a file
<?php
Class CreateXML{
public function xmlDeclaration(){
return $varxmlDec = "<?xml version='1.0'> ";...
|
by: vashwath |
last post by:
#include <stdio.h>
int main()
{
FILE *fp;
char s;
fopen("file.txt","w+");
fprintf(fp,"HI\n");
|
by: Anunay |
last post by:
Hi all,
Suppose a text file is given and we have to write a program that will
return a random line from the file. This can be easily done. But what
if the text file is too big and can't fit...
|
by: Roman Zeilinger |
last post by:
Hi
I have a beginner question concerning fscanf.
First I had a text file which just contained some
hex numbers:
0C100012
0C100012
....
|
by: Alien |
last post by:
Hi,
I have a question regarding the fopen( ) function. I wrote this piece of code:
#include <stdio.h>
int main()
{
FILE *fp;
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |