Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. NULL Char in a String ??

NULL Char in a String ??

Scheduled Pinned Locked Moved C / C++ / MFC
comsysadmindata-structurestutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex H 1983
    wrote on last edited by
    #1

    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

    I G 2 Replies Last reply
    0
    • A Alex H 1983

      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

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      As 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.

      1 Reply Last reply
      0
      • A Alex H 1983

        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

        G Offline
        G Offline
        gamitech
        wrote on last edited by
        #3

        why 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups