69,369
社区成员
发帖
与我相关
我的任务
分享
char * strncpy ( char * destination, const char * source, size_t num );
<cstring>
Copy characters from string
Copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of num characters have been written to it.
No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length of the C string in source is less than num.
Parameters
destination
Pointer to the destination array where the content is to be copied.
source
C string to be copied.
num
Maximum number of characters to be copied from source.
Return Value
destination is returned.
//你可以用这个,参考一下我上面的那个例子。能够实现其中的一块都可以的
//
#include <stdio.h>
#include <string.h>
int main()
{
char b[40];
scanf("%s",b);
//ch=copy_1(b,5,10);
printf("%s\n",b);
char newchar[100];
strcpy(newchar,b+5);
printf("%s\n",newchar);
return 0;
}