杂记之C语言实现复制函数strcpy和strcnpy

char *

strcpy(char *strDest, const char *strSrc){

         assert((strDest!=NULL) && (strSrc !=NULL)); //捕获异常,进行出错处理;

         char *address = strDest;

         while( (*strDest++ = * strSrc++) != ‘\0’ )

         NULL;

         return address ;

         //返回指针型参数

}

笔记摘自《高质量C++&C编程指南》 林锐

//A simple implementation of strncpy() might be:
char*
strncpy(char *dest, const char *src, size_t n){
               size_t i;

               for (i = 0 ; i < n && src[i] != '\0' ; i++)
                   dest[i] = src[i];
               for ( ; i < n ; i++)
                   dest[i] = '\0';//当src长度

               return dest;
}

笔记摘自man

你可能感兴趣的:(C语言)