memcpy(dest, src, n);
if n is less than the lenght of dest, something comes out:
static char dest[]="First";
static char src[]="Second";
memcpy(dest, src,3);
printf("\n target : %s", dest);
The output is "Secst"Try the following:
if(strlen(dest)>3)
{
for (i=0; dest[i] != '\0'; i++)
dest[i] = ' ';
dest[i] = '\0';
memcpy(dest, src, 3);
}
else
memcpy(dest, src, 3);
No comments:
Post a Comment