Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Removing EOF character from text files using COPY TO ... DELIMITED

165 views
Skip to first unread message

Chris Rizzo

unread,
Jan 2, 2001, 3:40:40 PM1/2/01
to
Hello,

I am using Clipper 5.2's "COPY TO <textfile> DELIMITED" command to create
text files for use with Microsoft Word's print merge. Word is having a
problem with the <EOF> character at the end of my text files created with
Clipper. Is there a way to get rid of this character, either during or
after the creation of these text files without having to edit each file
manually to delete the character?

Thanks in advance for all your help.

Christopher Rizzo

Paolo R.

unread,
Jan 2, 2001, 4:59:46 PM1/2/01
to

FUNCTION REMOVEEOF(filename)
LOCAL hw,rbuf
hw := FOPEN(filename,2) // open file r/w
FSEEK(hw,-1,2) //position at EOF-1
rbuf := SPACE(1)
FREAD(hw,@rbuf,1)
IF rbuf == CHR(26) //ensure last byte was EOF
FSEEK(hw,-1,1) // reposition at EOF-1
FWRITE(hw,"",0) // truncate file at filepos
ENDIF
FCLOSE(hw)
RETURN NIL

Regards
Paolo Ramozzi
paolo....@soft-com.it
www.soft-com.it


Lee Clinkscales

unread,
Jan 2, 2001, 5:10:16 PM1/2/01
to
"Chris Rizzo" <chris...@workscape.com> wrote in message
news:exPU0wPdAHA.269@cpmsnbbsa09...

Chris,

You'll want to include more error traps than you see below, but this is
the core of code that works for me. I'm not doing what you are, but
close enough for you to learn how to do exactly what you want. After you
have written the file with COPY TO, process it as below.
After you get a good idea of how low level file i/o works you might just
want to produce the text file directly. It's a whole lot more code, but
once you know how it all works, you'll use it many times in other
routines.

#include FILEIO.ch
...
FOPEN(nHandle... [fill in the rest]..)
...
FSEEK(nHandle, -1, FS_END)
IF FREADSTR(nHandle, 1) == Chr(26) // check for eof marker
//\ pointer just moved 1 byte as it read last byte.
FSEEK(nHandle, -1, FS_END) // step back over top of the byte just
read
ENDIF
FWRITE(nHandle, " ")
IF .not. FCLOSE(nLogHandle)
Alert("DOS ERROR: " + alltrim(str(FERROR()))+ "; Trying to close
file.")
ENDIF

I hope this gets you started in the right direction.

Lee

0 new messages