tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
22
Task/Copy-a-string/C/copy-a-string-2.c
Normal file
22
Task/Copy-a-string/C/copy-a-string-2.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdlib.h> /* exit() */
|
||||
#include <stdio.h> /* fputs(), printf() */
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char src[] = "Hello";
|
||||
char dst[80];
|
||||
|
||||
/* Use strlcpy() from <string.h>. */
|
||||
if (strlcpy(dst, src, sizeof dst) >= sizeof dst) {
|
||||
fputs("The buffer is too small!\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(src, '-', 5);
|
||||
printf("src: %s\n", src); /* src: ----- */
|
||||
printf("dst: %s\n", dst); /* dst: Hello */
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue