Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fputs - how can a text file have lines appended to it 1

Status
Not open for further replies.

jworley

Programmer
Jun 19, 2000
36
0
0
GB
Hi everyone

I have a routine that produces a text file for importing into an invoicing program, using fputs. I can create a new text file OK (fcreate), and have succeeded in writing to it, but I would like to re-open the file I created and add more lines to it at a later date. When I do this, I get a valid file handle returned but when I write lines to it using fputs, they don't get written. My code is:

&& Create the invoice file
fileHandle = fopen('invoice.csv') && Tried 12 & 2, no luck
if fileHandle = -1
&& File has been deleted, create a new one
fileHandle = fcreate('invoice.csv')
endif

&& Now some code that stores values from a table to a buffer


&& Put the new line in the text file
fputs(fileHandle,fileBuffer)

BTW, I don't want to use export as it is not appropriate for what I want to do. Any ideas anyone ??

Jim Worley
jim@aits-uk.net
15 years practical IT experience from sales to support to development plus B.Sc. (Hons) Computer Studies, fluent German speaker, willing to have a go at anything and don't suffer fools gladly !
 
I'd also recommend you reasearch the STRTOFILE() function with lAdditive argument. For Example,

=STRTOFILE(filebuffer,'invoice.csv',.T.)

If invoice.csv doesnt exist, its created. If it does exist, the contents of filebuffer is appended to it. Jon Hawkins

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
if file(whatever)
fopen(whatever)
fseek(fhandle,2,0) && look in help for fseek
* then fputs()
else
fcreate()
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top