Results 1 to 5 of 5

Thread: clear buffer in c + how to invert something?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    clear buffer in c + how to invert something?

    in continuation from previous post..

    Is there a function in C to clear a buffer?

    anything at all.


    2nd question:
    a rough idea: how can we invert a bytestream? or a block of data of any size...



    basically, the data has to be sent across the network, and the network data structure requires the bytestream be inverted. SO how to go about doin' that?
    Last edited by mendhak; Mar 28th, 2002 at 02:33 AM.

  2. #2
    amac
    Guest
    What do you mean clear a buffer?

    There is

    Code:
    char szBuffer[32];
    
    memset( szBuffer, 0, sizeof(buffer) / sizeof(char) );
    or

    Code:
    char szBuffer[32];
    
    ZeroMemory( szBuffer, sizeof(buffer) / sizeof(char) );
    Basically the same thing...


    and for your second question take a look at these fuctions: htons(), htonl(), ntohs(), ntohl()... They might help.

  3. #3
    jim mcnamara
    Guest
    Also you can completely clear the buffer from memory like thisL:

    Code:
    char *buf;
    buf = (char*) malloc(10000);
    // code here, then nuke the buffer
    free(buf);
    // or use new and delete (standard C++)which is like malloc and free.

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Thanks. Just what was needed.

  5. #5
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Beware of malloc and free (ie new and delete)..... You CANNOT free a buffer that was not created with malloc (or new). The result could be tragic!!

    Regards,
    MoMad
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width