微软给的strcpy函数有好多潜在问题。时间问题,抽时间再详析,直接上代码。
#include <stdio.h>
#include <string.h>
#define GENERIC
void *MyStrcpy( void *dst, const void GENERIC *src, unsigned int len )
{
unsigned char *pDst;
const unsigned char GENERIC *pSrc;
pSrc = src;
pDst = dst;
while ( len-- )
*pDst++ = *pSrc++;
return ( pDst );
}
void main()
{
char s[]="123456789";
char d[]="123";
char s1[]="123456789";
char d1[]="123";
strcpy(d,s);
printf("s=%s d=%s\n",s,d);
MyStrcpy(d1,s1,3);
printf("d1=%s s1=%s\n",s1,d1);
printf("s=0X%08X\nd=0X%08X\ns1=0X%08X\nd1=0X%08X\nstrcpy=0X%08X\nprintf=0X%08X\n",s,d,s1,d1,strcpy,printf);
}
运行结果: