Strncpy () [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]

/*

Copies count characters from the source string to the destination.

If count is less than the length of source, no null character is put

Onto the end of the copied string. If count is greater than the length

Of sources, DEST is padded with null characters to length count.

Copy the first n Bytes of the string ending with null in SRC to the array indicated by DeST.

If the first n Bytes of SRC do not contain null characters, the result will not end with null characters;

If the SRC length is less than n Bytes, fill the Dest with null until the n Bytes are completely copied.

The memory areas specified by Src and DEST cannot overlap and DEST must have enough space to hold SRC strings.

Returns the pointer to DeST.

*/

Char * my_strncpy (char * DEST, const char * Source, int count)

{

Char * P = DEST;

While (count & (* P ++ = * Source ++) count --;

While (count --)

* P ++ = '/0 ';

Return (DEST );

}

Int main ()

{

Char A [20];

Puts (my_strncpy (a, "ammana_babi", 15 ));

System ("pause ");

Return 0;

}

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.