#include <string.h>
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
#include <stdio.h>
#include <string.h>
int main()
{
char *src = "hello world";
printf("%s\n", strcpy(src,src));
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
char *src = "hello world";
char *dest = "yes";
printf("%s\n", strcpy(src, dest));
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
char buf[20] = "hello world";
char buf2[20];
strncpy(buf2, buf, 5);
printf("%s\n", buf2);
return 0;
}
beyes@linux-beyes:~/C/base> ./strncpy.exe
hello_xxxxx(乱码);
#include <stdio.h>
#include <string.h>
int main()
{
char buf[20] = "hello world";
char buf2[20];
strncpy(buf2, buf, 5);
buf2[5] = '\0'; /*添加 '\0' */
printf("%s\n", buf2);
return 0;
}
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |