Re: memset

Discussion in 'C Programming' started by Vladimir S. Oka, Mar 9, 2006.

  1. novice wrote:
    > can any body explain me the "memset()" function with example.


    Yes, a good textbook, or the C Standard:

    7.21.6.1 The memset function

    Synopsis
    1
    #include <string.h>
    void *memset(void *s, int c, size_t n);

    Description
    2 The memset function copies the value of c (converted to an unsigned
    char) into
    each of the first n characters of the object pointed to by s.

    Returns
    3 The memset function returns the value of s.

    My example (snippet):

    #include <stdio.h>
    #include <string.h>

    int main(void)
    {
    char name[] = "Vladimir";

    memset(name, 'X', strlen(name));
    printf("%s\n", name);

    return 0;
    }

    Should output "XXXXXXXX".

    --
    BR, Vladimir
    Vladimir S. Oka, Mar 9, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. k-man
    Replies:
    4
    Views:
    4,527
    Shelley Hebert
    Dec 18, 2003
  2. Joe C
    Replies:
    5
    Views:
    8,860
    tom_usenet
    Aug 24, 2004
  3. Replies:
    17
    Views:
    6,498
    Greg Comeau
    Sep 22, 2004
  4. Guest
    Replies:
    0
    Views:
    395
    Guest
    Sep 23, 2004
  5. Guest
    Replies:
    1
    Views:
    426
    Ron Natalie
    Sep 23, 2004
Loading...

Share This Page