1. void *memset (void *s,int c,size_t N)
Total effect: Sets the value of the first n bytes of the open memory space s to the value C.
2. Sample Example
# include
void Main () {
Char *s= "Golden Global View";
CLRSCR ();
memset (S, ' G ', 6);
printf ("%s", s);
GetChar ();
return 0;
}
3. The memset () function is often used for memory space initialization. Such as:
Char str[100];
memset (str,0,100);
4. memset () deep connotation: used to set up a memory space for all of a character, generally used in the definition of the string is initialized to ' or '/0 '; Example: Char A[100];memset (A, '/0 ', sizeof (a));
memcpy is used to make a memory copy, you can copy it regardless of the data type of object, can specify the length of the copy data; example: Char a[100],b[50]; memcpy (b, A, sizeof (b)); Note that using sizeof (a) will cause the memory address of B to overflow.
strcpy can only copy the string, it encounters '/0 ' on the end of the copy; for example: Char a[100],b[50];strcpy (A, B), if using strcpy (b,a), note the length of the string in a (the first '/ 0 ' before) if more than 50 bits, if exceeded, will cause the memory address of B to overflow.
5. Add: A little experience
Memset can easily empty a variable or array of a struct type.
Such as:
struct SAMPLE_STRUCT
{
Char csname[16];
int iSeq;
int iType;
};
For variables
struct Sample_strcut sttest;
In general, the method of emptying the sttest:
Sttest.csname[0]= '/0 ';
sttest.iseq=0;
sttest.itype=0;
It is convenient to use memset:
memset (&sttest,0,sizeof (struct sample_struct));
The assumption is an array:
struct sample_struct test[10];
The
memset (test,0,sizeof (struct sample_struct) *10);
6. strcpy
Prototype: extern char *strcpy (char *dest,char *src);
How to use: #i nclude
function: Copy the null-terminated string from SRC to the array referred to by Dest.
Description: The memory areas referred to by SRC and dest cannot overlap and dest must have sufficient space to accommodate the SRC string.
Returns a pointer to the dest.
memcpy
Prototype: extern void *memcpy (void *dest, void *src, unsigned int count);
How to use: #i nclude
Function: the memory area referred to by SRC is copied from count bytes to the memory area of Dest.
Description: The memory area referred to by SRC and dest cannot overlap, and the function returns a pointer to Dest.
Memset
Prototype: extern void *memset (void *buffer, int c, int count);
How to use: #i nclude
Function: Sets the first count bytes of the memory area indicated by buffer to character C.
Description: Returns a pointer to buffer.
memset function Specific Description