strcpy实现
#include <iostream> using namespace std; char *strcpy(char *strDest, const char *strSrc) { if ( strDest == NULL || strSrc == NULL) return NULL ; if ( strDest == strSrc) return strDest ; char *tempptr = strDest ; while((*strDest++ = *strSrc++) != '\0'); return tempptr ; } int main() { char strA[20]="ABCDEFGHIJKLMNOPQRS"; char* strB="how are you ?"; int length=strlen(strcpy(strA,strB)); //int lh=strlen(strncpy(strA,strB,sizeof(strA))); //printf("%s",strA); cout<<length<<endl; /*cout<<lh<<endl;*/ //char a[30] = "string(1)"; //char b[] = "string(2)"; //printf("before strncpy() : %s\n", a); //printf("after strncpy() : %s\n", strncpy(a, b, 8)); while(1); return 0; }