I have a question about fopen. I want to append text to a text file
already written. I think this is what I need to do. If I am correct fopen's
second parameter takes only 2 letters. I am using wt. To append text would I
need another call to fopen if my text file isn't already existing consisting
of wa or a+ ? How can I check if an existing text file exists that has been
created before ?
Bill 24 2903
In article <VgA5k.40538$lE3.23882@trnddc05>,
Bill Cunningham <no****@nspam.comwrote:
I have a question about fopen. I want to append text to a text file already written. I think this is what I need to do. If I am correct fopen's second parameter takes only 2 letters.
No, there are well-defined three-character sequences.
>I am using wt.
The standard does not define the meaning of 't', only of 'b' (binary).
Text is assumed if binary is not specified.
To append text would I need another call to fopen if my text file isn't already existing consisting of wa or a+ ? How can I check if an existing text file exists that has been created before ?
fopen() with 'a'. ftell() your current position, fseek() to the
beginning of the file, and ftell() again. If the first ftell()
result is the same as the second ftell() then you started out at
the beginning of the file and so there was no existing text.
(Note: If I recall correctly, in some systems when using text streams,
the initial file position is officially considered to be "one past"
the end of file, rather than right -at- the end of file. The writes
still work the same way, but if my memory is correct on this point,
then ftell() on a newly-created text file might not return the
same value as ftell() from the "beginning" of the same file.)
--
"Product of a myriad various minds and contending tongues, compact of
obscure and minute association, a language has its own abundant and
often recondite laws, in the habitual and summary recognition of
which scholarship consists." -- Walter Pater
"Bill Cunningham" <no****@nspam.comschreef in bericht
news:VgA5k.40538$lE3.23882@trnddc05...
I have a question about fopen. I want to append text to a text file
already written. I think this is what I need to do. If I am correct
fopen's second parameter takes only 2 letters. I am using wt. To append
text would I need another call to fopen if my text file isn't already
existing consisting of wa or a+ ?
read your favorite C book and try it out, its in there no matter if its a
good or bad book
On Jun 16, 11:44 pm, "Bill Cunningham" <nos...@nspam.comwrote:
I have a question about fopen. I want to append text to a text file
already written. I think this is what I need to do. If I am correct fopen's
second parameter takes only 2 letters. I am using wt.
People have already told you numerous times 't' is non-standard.
How many more times do you need to be told 't' is non-standard?
Here, once more: 't' is non-standard.
Just in case: 't' *is* *non*-standard.
"Serve Lau" <ni***@qinqin.comwrote in message
news:e8***************************@cache5.tilbu1.n b.home.nl...
read your favorite C book and try it out, its in there no matter if its a
good or bad book
Already checked it. I will check out the mentioned functions. Always
wondered what fpos did. I'll check ftell and such.
Bill
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:g3**********@canopus.cc.umanitoba.ca...
The standard does not define the meaning of 't', only of 'b' (binary).
Text is assumed if binary is not specified.
[snip]
I heard something about Microsoft and the 't'. If it isn't standard why use
it. What does M$ have to do with this anyway? I just won't use it anymore. I
will work with the functions you mentioned thanks very much.
Bill
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:g3**********@canopus.cc.umanitoba.ca...
I've tried this. Every new number overwites the last. Here is the code I can
see I don't know how to use fseek.
#include <stdio.h>
#include <stdlib.h>
int
main (int argc, char *argv[])
{
if (argc != 2)
{
puts ("usage error");
exit (EXIT_FAILURE);
}
double x;
x = strtod (argv[1], NULL);
FILE *fp;
fp = fopen ("data", "wa");
fprintf(fp,"%.2f\n",x);
ftell(fp);
fseek(fp,0,1);
ftell(fp);
fclose (fp);
return 0;
}
What did I do wrong?
Bill
<vi******@gmail.comwrote in message
news:2a**********************************@8g2000hs e.googlegroups.com...
People have already told you numerous times 't' is non-standard.
How many more times do you need to be told 't' is non-standard?
Here, once more: 't' is non-standard.
Just in case: 't' *is* *non*-standard.
Hum don't remember talking about it. I remember something mentioned
about M$ and t. Well no matter. I can see I can count on you for help that
is not needed. Have I not made to your killfile yet? What can I do to help?
You're in mine.
Bill
"Bill Cunningham" <no****@nspam.comwrote in message
news:66D5k.20948$3j2.17956@trnddc03...
>
"Serve Lau" <ni***@qinqin.comwrote in message
news:e8***************************@cache5.tilbu1.n b.home.nl...
You know my book doesn't give return values for these functions for
error checking. What about ftell and fseek do they return -1 or non zero
when successful ?
Bill
Bill Cunningham said:
<snip>
Have I not made to your killfile yet? What can I do
to help? You're in mine.
If he really were in your killfile, you would not have seen his article.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:_u******************************@bt.com...
If he really were in your killfile, you would not have seen his article.
I use OE. There's no killfile there. I just don't read posts from certain
persons. I know agent has a killfile. There comes a time to not read some
posts. A "killfile".
Bill
Bill Cunningham said:
>
"Bill Cunningham" <no****@nspam.comwrote in message
news:66D5k.20948$3j2.17956@trnddc03...
>> "Serve Lau" <ni***@qinqin.comwrote in message news:e8***************************@cache5.tilbu1. nb.home.nl...
You know my book doesn't give return values for these functions for
error checking.
In message <3d********@corp.newsgroups.com(posted on 20 July 2002) you
wrote:
"This little K&R2 book is giving me the devil of a time."
It is not unreasonable to deduce from that statement that you have had a
copy of K&R2 since at least 2002.
Despite your claim, K&R2 *does* document the return value semantics for
fopen, freopen, fflush, fclose, fprintf, fscanf, fgetc, fgets, fputc,
fputs, fread, fwrite, fseek, ftell, fgetpos, and fsetpos - on pp242-248.
What about ftell and fseek do they return -1 or non zero
when successful ?
Read the book.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Bill Cunningham said:
>
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:_u******************************@bt.com...
>If he really were in your killfile, you would not have seen his article.
I use OE. There's no killfile there.
Then he can't be in one, can he?
I just don't read posts from certain persons.
If that were true, you would not have read his article, so there would have
been no cause to respond to it.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"Bill Cunningham" <no****@nspam.comwrites:
I have a question about fopen. I want to append text to a text file
already written. I think this is what I need to do. If I am correct fopen's
second parameter takes only 2 letters. I am using wt. To append text would I
need another call to fopen if my text file isn't already existing consisting
of wa or a+ ? How can I check if an existing text file exists that has been
created before ?
Bill
Try reading the man page Bill. I hear it helps.
"Bill Cunningham" <no****@nspam.comwrites:
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:g3**********@canopus.cc.umanitoba.ca...
>The standard does not define the meaning of 't', only of 'b' (binary). Text is assumed if binary is not specified.
[snip]
I heard something about Microsoft and the 't'. If it isn't standard why use
it. What does M$ have to do with this anyway? I just won't use it anymore. I
will work with the functions you mentioned thanks very much.
Bill
Alright, give it up Kenny. It's not funny anymore :-)
In article <%GE5k.40579$lE3.1104@trnddc05>,
Bill Cunningham <no****@nspam.comwrote:
fp = fopen ("data", "wa");
I said to use "a", not "wa".
--
"MAMA: Oh--So now it's life. Money is life. Once upon a time freedom
used to be life--now it's money. I guess the world really do change.
WALTER: No--it was always money, Mama. We just didn't know about it."
-- Lorraine Hansberry
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:g8******************************@bt.com...
Bill Cunningham said:
>> "Bill Cunningham" <no****@nspam.comwrote in message news:66D5k.20948$3j2.17956@trnddc03...
>>> "Serve Lau" <ni***@qinqin.comwrote in message news:e8***************************@cache5.tilbu1 .nb.home.nl...
You know my book doesn't give return values for these functions for error checking.
In message <3d********@corp.newsgroups.com(posted on 20 July 2002) you
wrote:
"This little K&R2 book is giving me the devil of a time."
It is not unreasonable to deduce from that statement that you have had a
copy of K&R2 since at least 2002.
Despite your claim, K&R2 *does* document the return value semantics for
fopen, freopen, fflush, fclose, fprintf, fscanf, fgetc, fgets, fputc,
fputs, fread, fwrite, fseek, ftell, fgetpos, and fsetpos - on pp242-248.
>What about ftell and fseek do they return -1 or non zero when successful ?
Read the book.
I may have to break it out. I have a little pocket reference I've leafed
though. Couldn't find return values. Well I'll get them.
Bill
On Jun 17, 8:35 am, "Bill Cunningham" <nos...@nspam.comwrote:
"Richard Heathfield" <r...@see.sig.invalidwrote in message
news:g8******************************@bt.com...
Bill Cunningham said:
"Bill Cunningham" <nos...@nspam.comwrote in message news:66D5k.20948$3j2.17956@trnddc03...
>"Serve Lau" <ni...@qinqin.comwrote in message news:e8***************************@cache5.tilbu1 .nb.home.nl...
You know my book doesn't give return values for these functions for
error checking.
In message <3d38f60...@corp.newsgroups.com(posted on 20 July 2002) you
wrote:
"This little K&R2 book is giving me the devil of a time."
It is not unreasonable to deduce from that statement that you have had a
copy of K&R2 since at least 2002.
Despite your claim, K&R2 *does* document the return value semantics for
fopen, freopen, fflush, fclose, fprintf, fscanf, fgetc, fgets, fputc,
fputs, fread, fwrite, fseek, ftell, fgetpos, and fsetpos - on pp242-248.
What about ftell and fseek do they return -1 or non zero
when successful ?
Read the book.
I may have to break it out. I have a little pocket reference I've leafed
though. Couldn't find return values. Well I'll get them.
Bill
/* Code not compiled */
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[]) {
double x;
FILE *fp;
x = strtod(argv[1], NULL);
fp = fopen("foo", "a+");
fprintf(fp, "%.2f", x);
fclose(fp);
return 0;
}
Probably this is what you want to do. The mode "a+" means open for
appending and reading as well. Its not required if you just wish to
append to the file.
Return type for ftell is long. fseek returns int ( -1 on error, 0
otherwise ). If you are on linux/unix box, use the man pages. If you
are on a windows machine and using Visual Studio, you can use MSDN.
Its better to have the documentation handy.
"Bill Cunningham" <no****@nspam.comwrote in message
news:5iG5k.66404$bs3.8292@trnddc07...
>
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:g8******************************@bt.com...
>Bill Cunningham said:
>>> "Bill Cunningham" <no****@nspam.comwrote in message news:66D5k.20948$3j2.17956@trnddc03...
"Serve Lau" <ni***@qinqin.comwrote in message news:e8***************************@cache5.tilbu 1.nb.home.nl...
You know my book doesn't give return values for these functions for error checking.
In message <3d********@corp.newsgroups.com(posted on 20 July 2002) you wrote:
"This little K&R2 book is giving me the devil of a time."
It is not unreasonable to deduce from that statement that you have had a copy of K&R2 since at least 2002.
Despite your claim, K&R2 *does* document the return value semantics for fopen, freopen, fflush, fclose, fprintf, fscanf, fgetc, fgets, fputc, fputs, fread, fwrite, fseek, ftell, fgetpos, and fsetpos - on pp242-248.
>>What about ftell and fseek do they return -1 or non zero when successful ?
Read the book.
I may have to break it out. I have a little pocket reference I've
leafed though. Couldn't find return values. Well I'll get them.
http://www.opengroup.org/onlinepubs/...xsh/fopen.html http://www.opengroup.org/onlinepubs/...sh/fclose.html http://www.opengroup.org/onlinepubs/...xsh/fread.html http://www.opengroup.org/onlinepubs/...sh/fwrite.html http://www.opengroup.org/onlinepubs/...sh/fflush.html http://www.opengroup.org/pubs/online...h/fgetpos.html http://www.opengroup.org/pubs/online...h/fsetpos.html http://www.opengroup.org/onlinepubs/...sh/fscanf.html http://www.opengroup.org/onlinepubs/...ons/fputs.html http://www.opengroup.org/onlinepubs/...ons/fputc.html http://www.opengroup.org/onlinepubs/...ons/fgets.html http://www.opengroup.org/onlinepubs/...ons/fgetc.html http://www.opengroup.org/onlinepubs/...ns/ferror.html http://www.opengroup.org/onlinepubs/...ions/feof.html http://www.opengroup.org/onlinepubs/...ons/ftell.html http://www.opengroup.org/onlinepubs/...ons/fseek.html http://www.opengroup.org/onlinepubs/...ns/fgetwc.html http://www.opengroup.org/onlinepubs/...ns/fgetws.html http://www.opengroup.org/onlinepubs/...s/freopen.html
ect... http://www.opengroup.org/
is you friend!
Bill Cunningham wrote:
"Richard Heathfield" <rj*@see.sig.invalidwrote:
><3d********@corp.newsgroups.com(posted on 20 July 2002) you wrote:
"This little K&R2 book is giving me the devil of a time."
It is not unreasonable to deduce from that statement that you have had a copy of K&R2 since at least 2002.
Despite your claim, K&R2 *does* document the return value semantics for fopen, freopen, fflush, fclose, fprintf, fscanf, fgetc, fgets, fputc, fputs, fread, fwrite, fseek, ftell, fgetpos, and fsetpos - on pp242-248.
>>What about ftell and fseek do they return -1 or non zero when successful ?
Read the book.
I may have to break it out. I have a little pocket reference
I've leafed though. Couldn't find return values.
You should never have hidden it. It answers virtually every
question you have asked here.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Serve Lau wrote:
"Bill Cunningham" <no****@nspam.comschreef in bericht
>I have a question about fopen. I want to append text to a text file already written. I think this is what I need to do. If I am correct fopen's second parameter takes only 2 letters. I am using wt. To append text would I need another call to fopen if my text file isn't already existing consisting of wa or a+ ?
read your favorite C book and try it out, its in there no matter
if its a good or bad book
You appear to devote your time to telling people not to ask
questions, using incorrect punctuation.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
"CBFalconer" <cb********@yahoo.comschreef in bericht
news:48***************@yahoo.com...
Serve Lau wrote:
>"Bill Cunningham" <no****@nspam.comschreef in bericht
>>I have a question about fopen. I want to append text to a text file already written. I think this is what I need to do. If I am correct fopen's second parameter takes only 2 letters. I am using wt. To append text would I need another call to fopen if my text file isn't already existing consisting of wa or a+ ?
read your favorite C book and try it out, its in there no matter if its a good or bad book
You appear to devote your time to telling people not to ask
questions, using incorrect punctuation.
Please show me my posts that justifies this general statement. Also please
dont criticize my puntuation, it makes me feel VERY bad.
Serve Lau wrote:
"CBFalconer" <cb********@yahoo.comschreef:
>Serve Lau wrote:
>>"Bill Cunningham" <no****@nspam.comschreef in bericht
I have a question about fopen. I want to append text to a text file already written. I think this is what I need to do. If I am correct fopen's second parameter takes only 2 letters. I am using wt. To append text would I need another call to fopen if my text file isn't already existing consisting of wa or a+ ?
read your favorite C book and try it out, its in there no matter if its a good or bad book ^^
^^ You appear to devote your time to telling people not to ask questions, using incorrect punctuation.
Please show me my posts that justifies this general statement. Also
please dont criticize my puntuation, it makes me feel VERY bad.
^^
Alright, I'll ignore punctuation. :-) As for general statements,
the quotation above will do.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
"CBFalconer" <cb********@yahoo.comschreef in bericht
news:48***************@yahoo.com...
>Please show me my posts that justifies this general statement. Also please dont criticize my puntuation, it makes me feel VERY bad.
^^
Alright, I'll ignore punctuation. :-) As for general statements,
the quotation above will do.
get out more
"Serve Lau" <ni***@qinqin.comwrote:
"CBFalconer" <cb********@yahoo.comschreef in bericht
news:48***************@yahoo.com...
Please show me my posts that justifies this general statement. Also
please dont criticize my puntuation, it makes me feel VERY bad.
^^
Alright, I'll ignore punctuation. :-) As for general statements,
the quotation above will do.
get out more
Leer je talen correct schrijven, dwaze Belg. Je bent een belediging voor
het Nederlandse taalgebied.
Richard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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: typingcat |
last post by:
Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();...
|
by: git_cs |
last post by:
Hey, guys and gals
Somedays ago, I had asked for the DES algorithm in C language.
Although I have written the algorthim in C myself, I am facing a
peculiar problem, which I hope some of u guys and...
|
by: Grocery Clerk |
last post by:
I know open() returns a file descriptor and fopen() returns a pointer
to FILE. The question is, when do I use fopen() and when do I use
open()? Could someone give me an example when to use one...
|
by: Sathyaish |
last post by:
If fopen fails, is there a way to know why?
| |
by: Blue |
last post by:
Hi ,
Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".
I know that "open" /"read" / "write" are system calls and "fopen"...
|
by: pjlsr |
last post by:
It's close to twenty years since I used the C language and at that time
I was doing only floating point computational work, nothing with
strings or reading files. I tried to use fopen in the...
|
by: Jae |
last post by:
Real(const string &fileName)
{
FILE * myInputFile = fopen(fileName, "rt");
.....
fclose(myInputFile);
|
by: Julia |
last post by:
Hi, there,
I am trying to append a binary file by using:
FILE *strean;
stream = fopen( "c:\temp.dat", "ba+" ));
Is there a way that I can check if the file exists or not before
fopen,...
|
by: subramanian100in |
last post by:
Consider the following program:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv)
{
if (argc != 2)
{
printf("Usage: <program-name<text-file>\n");
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |