本帖最后由 jackz007 于 2022-4-24 18:03 编辑
偷懒写的#include <stdio.h>
#include <string.h>
char * strncpy_ch(char * dest , const char * source , size_t count , size_t begin)
{
return strncpy(dest , & source[begin] , count) ;
}
自己写的#include <stdio.h>
char * strncpy_ch(char * dest , const char * source , size_t count , size_t begin)
{
int c , i , n ;
for(c = n = 0 ; source[n] ; n ++) ;
if(n > 0 && count < n) for(c = 0 , i = begin ; c < count && source[i] ;) dest[c ++] = source[i ++] ;
dest[c] = '\0' ;
return dest ;
}
|