函数原型如下:
char *strcpy(char *strDest, const char *strSrc) { char *address=strDest; assert((strDest!=NULL) && (strSrc!=NULL)); while(*strSrc!=‘\0‘) { *strDest++=*strSrc++; } *strDest=‘\0‘; return address; } char *strcat(char *strDest, const char *strSrc) { char *address=strDest; assert((strDest!=NULL) && (strSrc!=NULL)); while(*strDest!=‘\0‘) { strDest++; } while(*strSrc!=‘\0‘) { *strDest++ =* strSrc++; } *strDest=‘\0‘; return address; }
//增强版的字符串复制和字符串拼接函数 char *strcpy_s(char *strDest, int len, const char *strSrc) { char *address=strDest; int i = 0; assert((strDest!=NULL) && (strSrc!=NULL) && (size)); while(*strSrc!=‘\0‘) { *strDest++=*strSrc++; i++; assert(i<=len); } *strDest=‘\0‘; return address; } char *strcat(char *strDest, int len, const char *strSrc) { char *address=strDest; int i = 0; assert((strDest!=NULL) && (strSrc!=NULL)); while(*strDest!=‘\0‘) { strDest++; i++; } while(*strSrc!=‘\0‘) { *strDest++ =* strSrc++; i++; assert(i<=len); } *strDest=‘\0‘; return address; }
时间: 2024-12-20 15:37:03