NULL Char in a String ??
-
hi i am using MSWinSock Activex in my project to Create a Simple TCP connection through a server. for this purpose i have to Send an Message to that Server. My message should Contain Some NULL char char(0) in it. for example my message should be something like this :
HI***This is Ehsan******Accept my request
(here * means char(0) or NULL char ) MSWinSock Uses this Syntax to send a Message :void CMSWinsockControl::SendData(const VARIANT& data)
this means that i have to Save my message in a VARIANT type variable and then Send it with this function. in VARIANT i can use BSTR to store my message in VARIANT but as u know Char(0) means the end of a String So i need to Store my message in a Different way in VARIANT variable. one way is to store a Char[] (an array of char) in a Variant !! is it Possible ?? Thankx a lot -
hi i am using MSWinSock Activex in my project to Create a Simple TCP connection through a server. for this purpose i have to Send an Message to that Server. My message should Contain Some NULL char char(0) in it. for example my message should be something like this :
HI***This is Ehsan******Accept my request
(here * means char(0) or NULL char ) MSWinSock Uses this Syntax to send a Message :void CMSWinsockControl::SendData(const VARIANT& data)
this means that i have to Save my message in a VARIANT type variable and then Send it with this function. in VARIANT i can use BSTR to store my message in VARIANT but as u know Char(0) means the end of a String So i need to Store my message in a Different way in VARIANT variable. one way is to store a Char[] (an array of char) in a Variant !! is it Possible ?? Thankx a lotAs a BSTR includes the size of the string (rather than relying on null termination), it should exactly suit your needs. Just a quick look at CComBSTR:
CComBSTR( );
CComBSTR( int nSize );
CComBSTR( int nSize, LPCOLESTR sz );
CComBSTR( int nSize, LPCSTR sz );nSize
[in] The number of characters to copy from sz.
sz
[in] A string to copy. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR. Only nSize characters will be copied. The default value is NULL.
So that *should* sort out your problem. Iain.
-
hi i am using MSWinSock Activex in my project to Create a Simple TCP connection through a server. for this purpose i have to Send an Message to that Server. My message should Contain Some NULL char char(0) in it. for example my message should be something like this :
HI***This is Ehsan******Accept my request
(here * means char(0) or NULL char ) MSWinSock Uses this Syntax to send a Message :void CMSWinsockControl::SendData(const VARIANT& data)
this means that i have to Save my message in a VARIANT type variable and then Send it with this function. in VARIANT i can use BSTR to store my message in VARIANT but as u know Char(0) means the end of a String So i need to Store my message in a Different way in VARIANT variable. one way is to store a Char[] (an array of char) in a Variant !! is it Possible ?? Thankx a lotwhy don't yopu try the void *memset( void *dest, int c, size_t count ); function which inits the memory of a string with a given char on a certain length; or char *_strset( char *string, int c ); char *_strnset( char *string, int c, size_t count ); #include #include void main( void ) { char string[15] = "This is a test"; /* Set not more than 4 characters of string to be *'s */ printf( "Before: %s\n", string ); _strnset( string, '*', 4 ); printf( "After: %s\n", string ); } Output Before: This is a test After: **** is a test I hope this helped. gabby