[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;
}