Copy Code code as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
memcpy: Copying by byte
Prototype: extern void* memcpy (void *dest,void *src,unsigned int count)
Function: Copy count bytes from the memory area referred to by SRC to the memory area referred to by dest;
With strcpy
void *memcpy_su (void *dest, void *src, unsigned int count)
{
ASSERT ((dest!=null) && (src!=null));
char* bdest = (char*) dest;
char* bsrc = (char*) src;
while (count-->0)
*bdest++ = *bsrc++;
return dest;
}
strcpy: Copy string, and end with ' I '
Prototype: extern char *strcpy (char *dest,char *src)
function: To copy the string src refers to the end of ' dest ' to the array of the reference;
Description: The areas of memory that Src and dest refer to are not overlapped and dest must have enough space to hold the string. Returns the Dest pointer.
Char *strcpy_su (char *dest,char *src)
{
ASSERT ((dest!=null) && (src!=null));
char *address = dest;
while ((*dest++=*src++)!= ' ")
Continue
return dest;
}
Memset: Sets the first count byte of the memory area referred to by buffer, substituting character C for
Prototype: extern void *memset (void *buffer,int c,int count);
void *memset_su (void *buffer, int c, int count)
{
ASSERT ((buffer!=null));
char* buffer2 = (char*) buffer;
while (count-->0)
*buffer2++ = C;
return buffer;
}
void Main ()
{
Char str1[100]= "Abchjhgjghjgjgh";
Char str2[50]= "EFGHDFKDJF";
strcpy (str1, str2);
printf ("%s\n", str1);
Char a[3];
Memset (A, ' a ', sizeof (a)-1);
memset (&a[2], ' n ', 1);
printf ("%s\n", a);
memcpy (str1, str2, strlen (str2));
printf ("%s\n", str1);
}