222k views
4 votes
The _________ function copies, at most, n number of characters from one string to another.

A) strncpy()
B) strncat()
C) strcpy()
D) strcat()

User Mayuko
by
8.7k points

1 Answer

4 votes

Final answer:

The strncpy() function is used to copy a specified number of characters from one string to another in C programming, preventing buffer overflow issues by limiting the number of characters copied.

Step-by-step explanation:

The function that copies, at most, n number of characters from one string to another is strncpy(). This function is used in the C programming language to copy a specified number of characters from a source string to a destination string. If the length of the source string is less than n characters, null characters are added to the destination to maintain the character count. Unlike strcpy(), which does not specify a limit and may lead to buffer overflows, strncpy() enhances program stability by preventing such issues when used correctly.

User TeamTam
by
8.2k points