Definition | #include <string.h> char *strfill(char *s1, const char *s2, size_t n);
The manner in which copying takes place is determined by the lengths and contents of strings s1 and s2 and the value specified for n.
|
Return val. | Pointer to the result string s1. |
Notes | Strings terminated with the null byte (\0) are expected as arguments.
The behavior is undefined if memory areas overlap. |
Example | #include <stdio.h>
#include <string.h>
int main(void)
{
size_t n;
char s1[10];
char s2[10];
printf("Please input 2 strings!\n");
scanf("%s %s", s1, s2);
printf("Copy how many characters?\n");
scanf("%d", &n);
strfill(s1, s2, n);
/* strfill(s1, NULL, n); Example of the transfer of s2 as a
NULL pointer */
*(s1 + n) = '\0'; /* Terminate result string with null byte */
printf("s1 after strfill: %s\n", s1);
printf("Current length of s1: %d\n", strlen(s1));
return 0;
}
|
See also | strncpy |