Thread: Memset

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    10

    Memset

    I understand that memset sets the first num of bytes in memory block pointed to by ptr with value given.

    Code:
    void * memset ( void * ptr, int value, size_t num );
    Lets say I do the following:

    Code:
    char data[12];		                                      
    memset(data, 0x0A, sizeof(data));
    Would data look something like "10101010101\0"?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You mean in binary? No, but that is a correct decimal representation.

    I'm assuming you don't actually want a character string, but there is no terminating zero either.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, the binary value would be 00001010 00001010 <another 9> 00001010. There will not be any terminating zero, as memset is given sizeof(data), it will fill ALL bytes of the array.

    As a string, you could do the same thing as
    Code:
    char data[12] = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    Again you there is no terminating zero, as there is 12 newlines in the array.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    10
    Thanks guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. info on memset and recv
    By lolguy in forum Networking/Device Communication
    Replies: 15
    Last Post: 11-12-2009, 05:48 AM
  2. Question about memset
    By Mortissus in forum C Programming
    Replies: 3
    Last Post: 03-24-2009, 08:16 AM
  3. Simple Question on Correct Usage of memset
    By deadpoet in forum C++ Programming
    Replies: 2
    Last Post: 03-16-2004, 08:58 AM
  4. memset has conflicting declaration
    By mangoMan in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2004, 10:08 AM
  5. memset() or ZeroMemory()
    By jdinger in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2002, 09:38 AM