Posted By
   SVS on 2008-02-08 13:51:25
   |   Writing CHR$(0)
  Hello, does anybody know if the command PRINT# has problems to write on disk the NULL character ($00)? I've met some problems, maybe they come from the string where I stored the $00. I mean that it could be that a string with only $00 has null lenght?!
  |   
 | 
Posted By
   siz on 2008-02-09 03:17:19
  |   Re: Writing CHR$(0)
  AFAIK BASIC stores strings with a terminating null character, thus it cannot read and write chr$(0) characters.   And yes: a string with only a chr$(0) means an empty string.
  |   
 | 
Posted By
   SVS on 2008-02-09 04:35:44
   |   Re: Writing CHR$(0)
  1) Does this mean that is is impossible to write a byte with $00 inside any file? 2) I've tried this: A$=chr$(0)+chr$(0): ? LEN(A$) the result is 2.
  |   
 | 
Posted By
   Rachy on 2008-02-09 05:02:21
  |   Re: Writing CHR$(0)
  BASIC does not store strings in null-terminated form. You can store 0 character value in strings, also you can use PRINT# command to store it in files. I don't know what went wrong in your case, SVS.
  I have just tested it with Yape in IEC mode: OPEN1,8,1,"TEST" RINT#1,"ABC"+CHR$(0)+"DEF":CLOSE1
  The content of the file is: 41 42 43 00 44 45 46 0D
  |   
 | 
Posted By
   Rachy on 2008-02-09 05:03:02
  |   Re: Writing CHR$(0)
  Ookay, the smiley is colon (  and P, obviously...  
  |   
 | 
Posted By
   Rachy on 2008-02-09 05:03:51
  |   Re: Writing CHR$(0)
  Pff...  
  So: colon ( : ) and P...  
  |   
 | 
Posted By
   siz on 2008-02-09 15:30:29
  |   Re: Writing CHR$(0)
  Sorry. So my memory does not serve me well.   Only the BASIC INPUT# and GET# has problems with CHR$(0): they sense it as an EOF. I tested with this simple program:
  10 A$="ABC"+CHR$(0)+"DEF"                20 PRINTLEN(A$), A$                      30 OPEN1,8,1,"TEST" RINT#1,A$:CLOSE1    40 OPEN1,8,0,"TEST":INPUT#1,B$:CLOSE1    50 PRINTLEN(B$), B$                                                               READY.                                   RUN                                       7        ABCDEF                          3        ABC                                                                     READY.
  |   
 | 
Posted By
   siz on 2008-02-09 15:31:06
  |   Re: Writing CHR$(0)
  Oops, my : P become a smiley too...  
  |   
 | 
Posted By
   SVS on 2008-02-10 07:37:15
   |   Re: Writing CHR$(0)
  SIZ, from my tests the CHR$(0) is not stored inside the file by PRINT#. Infact reading data a byte a time by GET#, the resulting string is without the CHR$(0).
  Example:  PRINT# "abc"+CHR$(0)+"def" GET#  B$.....A$=A$+B$ (7 times) Result string A$ is "abcdef" (6 characters long)
  Does this result to you too?
  |   
 | 
Posted By
   JamesC on 2008-02-10 11:52:30
  |   Re: Writing CHR$(0)
  The system has to be able to write and read CHR$(0), otherwise BASIC End-of-Line markers would be destroyed when a program was reloaded. 
  Are you using any custom load/save routines (including fastloaders)? 
  Does your program absolutely REQUIRE the CHR$(0)? Could you substitute another marker and then replace the marker upon reloading? ie: 1300 OPEN 8,8,8,"somefile,u,r" : DO 1310 GET#8, A$, B$ : IF A$ = CHR$(255) ANB B$ = CHR$(1) THEN A$ = CHR$(0) : B$ = "" 1320 DA$ = DA$ + A$ + B$ : LOOP UNTIL ST = 64
  |   
 | 
Posted By
   TNT/BF on 2008-02-10 14:22:37
  |   Re: Writing CHR$(0)
  When you read CHR$(0) you need to do it this way:
  ... 100 GET #8,A$:IF A$="" THEN A$=CHR$(0) ...
  because BASIC returns empty string for CHR$(0).
  (Works on C64 at least  )
  |   
 |