Writing nulls to a file 
Author Message
 Writing nulls to a file

Does anyone know how to write nulls to a file?  For example, I have an
int digits[100] array that has the follwoing values:

digits[0] = 0
digits[1] = 0
digits[2] = 1
digits[3] = 0
digits[4] = 0
digits[5] = 13

I have a routine that translates this to PACKED form:
unsigned char pbuf[100]

pbuf[0] = NULL (ASCII '\0')
pbuf[1] = SLE  (ASCII 16)
pbuf[2] = CR   (ASCII 13)

I want to write pbuf to a file but it does not write anything because
it stops at the first null (pbuf[0]).

Now, before I get a bunch of e-mails explaining that this is by design,
I realize this.  What I am trying to do in the bigger picture is write
a routine to convert a number to a PACKED decimal.  The number about in
pbuf would be -100.  The above number in PACKED representation is:

00000000   = ASCII 0  = NULL
00010000   = ASCII 16 = SLE
00001101   = ASCII 13 = CR

I have the conversion working well and can go between ASCII and PACKED
but when I try to save the PACKED version, nothing is saved because the
first character is '\0' which of course signifies the end of the string.

Any thoughts?
--Patrick

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 31 Jul 2002 03:00:00 GMT  
 Writing nulls to a file

Quote:

>I have the conversion working well and can go between ASCII and PACKED
>but when I try to save the PACKED version, nothing is saved because the
>first character is '\0' which of course signifies the end of the string.

>Any thoughts?

Don't use functions that write strings to a file.  Use a block read
and block write operation, and open the file in binary mode.

Mike

--

"Genius gives birth, talent delivers."

           -- Jack Kerouac

(Remove NOSPAM, if present, to reply via email)



Wed, 31 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Writing a null terminated charater to file

2. Writing NULLs to a binary file

3. null pointer write

4. Multiple writing to /dev/null

5. how to write a function that returns a string of N nulls

6. Writing readable code (what is NULL)

7. writing 255 to a byte field becomes NULL in DAO

8. UNIX written in C (was Re: why null-ter

9. Unix written in C (was Re: Why null

10. Writing a NULL Date to an Access DB using COleDateTime

11. COleDateTime and NULL (writing to DB)

12. using write() to write a struct to a file

 

 
Powered by phpBB® Forum Software