Memset () [C language library function source code]

Source: Internet
Author: User

[C language library function source code]

[This program is compiled in Dev C ++ 4.9.9.2]

/*

Sets the first "count" bytes of the memory starting at "DST"

To the character value "Val ".

Set the first count bytes of the memory area referred to by DST to Val. Returns the pointer to DST.

In practical applications, we sometimes use the malloc function to apply for some memory space.

Memory space sometimes needs initialization. memset is often used for initialization.

For example:

Int * P;

P = (int *) malloc (0x400 * sizeof (INT ));

Memset (p, 400 X );

*/

Void * my_memset (void * DST, int Val, int count)

{

Void * P = DST;

While (count --)

{

* (Char *) DST = (char) val;

DST = (char *) DST + 1;

}

Return P;

}

Int main ()

{

Char STR [] = "ammana_babi ";

My_memset (STR, 'z', strlen (STR ));

Puts (STR );

System ("pause ");

Return 0;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.