Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: If NULL End...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 19 of 19 Topic 4067 of 4370
Post > Topic >>

Re: If NULL Ends a String or Char[], How to Send NULL to a File?

by "Ed Norris" <ed_norris@[EMAIL PROTECTED] > Mar 15, 2008 at 08:05 PM

You already have a bunch of correct replies, but here is my 2 cents.

Writing c++, I prefer using strings to char arrays for any type of data
like 
that.

Say you're making a call that requires a buffer of a maximum size.  I
prefer

string buffer;
buffer.resize(MAX_BUFFER_SIZE);

WindowsAPICall(inputVar, (char *)buffer.data(), buffer.length() );

// use buffer

This is what I did when adding multistring sup****t to our Windows registry

library and it removed concerns about resource deallocation when an 
exception occurred.  (Note that I'm not saying that memory leaks will 
necessarily occur with any other solution)

Two problems with my approach are
1. Any string handling functions that consider a null byte to be the end
of 
the string will fail (mentioned earlier in the thread)
2. Your IDE may not show the entire contents of the string

Criticism welcomed,
Ed

"Hal Vaughan" <hal@[EMAIL PROTECTED]
> wrote in message 
news:RA5Cj.7517$z13.4208@[EMAIL PROTECTED]
>I have a series of codes that will include NULL bytes and other non-text
> data that I need to send to a device through a file.
>
> Since a NULL terminates a string, how do I send a string containing NULL
> bytes to a file (or device, depending on the OS)?
>
> Do I have to handle the string (or char[]) in a special way to make sure

> all
> the data is kept intact?
>
> Is there a better way to handle this?
>
> Thanks!
>
> Hal
 




 19 Posts in Topic:
If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 08:28:33 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 10:33:41 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 13:38:19 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 14:00:08 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 14:27:55 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 14:35:06 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 14:38:36 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 16:14:14 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 16:47:31 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"R. Scott Mellow&quo  2008-03-13 13:07:37 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 18:59:08 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ralph D. Ungermann&  2008-03-13 15:03:06 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 16:56:49 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 17:04:36 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Anand Hariharan <mailt  2008-03-13 15:45:18 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ralph D. Ungermann&  2008-03-13 14:38:28 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Philip Potter <pgp@[EM  2008-03-13 16:20:55 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ralph D. Ungermann&  2008-03-13 18:57:23 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ed Norris" <  2008-03-15 20:05:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 11:48:45 CST 2008.