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

Writing NULL-char to file

124 views
Skip to first unread message

DQ Ninh

unread,
Feb 2, 1999, 3:00:00 AM2/2/99
to
I think you must open the file in binary mode.

Andrzej Sulej wrote in message <3541B4E1...@fiber.net.pl>...
>Hi,
>I have a problem with null-char.
>I would like to write a "null" to a file (ascii file )
>I tried this but no result :
>--------------------------------------------------------------
>integer li_FileNum, i
>string emp_id_pic [1 to 11]
>
>li_FileNum = FileOpen("C:\rs\tescik.txt", StreamMode!, Write!, Shared!,
>Replace!)
>
>emp_id_pic[1] = "a"
>emp_id_pic[2] = "~000"
>emp_id_pic[3] = "b"
>emp_id_pic[4] = "~h00"
>emp_id_pic[5] = "c"
>emp_id_pic[6] = ""
>emp_id_pic[7] = "d"
>setnull(emp_id_pic[8])
>emp_id_pic[9] = "e"
>emp_id_pic[10] = char(0)
>emp_id_pic[11] = "f"
>
>FOR i=1 TO 11
> FileWrite(li_FileNum, emp_id_pic[i])
>NEXT
>FileClose(li_FileNum)
>--------------------------------------------------------
>The file "tescik.txt" has 6 bytes and look like (HEX mode):
>61 62 63 64 65 66 | a b c d e f
>
>I would like to use a null character to send to RS COMM with
>mscomm32.ocx. There is not possible to do that.
>The same problem received ce...@cevi.be (CEVI - JV) in message
>Subject: NULL character in a PB String
>Date: Fri, 31 Oct 1997 14:11:00 GMT
>
>Has anybody help me ?
>
>an...@fiber.net.pl
>www.fiber.net.pl
>www.fibermedia.pl
>www.terminal.pl
>

werner.f...@esn-bochum.de

unread,
Feb 3, 1999, 3:00:00 AM2/3/99
to

The problem is, that PowerScript strings are stored in good ol'
C ASCIIZ format, i.e., a NULL byte terminates the string! Hence, writing
ls_something = "~000" is like storing two NULL bytes in a row, but
ls_something still equals "" (the empty string). So, PowerScript would
execute the THEN block of the following if:
if "" = "~000" then
messagebox("Null bytes", "vanish from strings")
end if
The solution might be to use a blob; that's the 2nd type allowed for
FileWrite()'s second argument:
Blob lbl_null
lbl_null = Blob("1") // Build blob sized 1 byte
char lch_null
lch_null = char(0)
BlobEdit(lbl_null, 1, lch_null) // Change 1st byte to NULL
FileWrite(li_handle, lbl_null)
where li_handle points to a file opened in StreamMode!.
Maybe this works...

HTH, Werner

In article <9OjywMwT#GA....@forums.powersoft.com>,

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

0 new messages