0
点赞
收藏
分享

微信扫一扫

C语言里的几个拷贝函数memcpy、memset、strcpy、strncpy


#include<string.h>

1. src和dest所指内存区域不能重叠,函数返回指向dest的指针。memcpy用来做内存拷贝,你可以拿它拷贝任何数据类型的对象,可以指定拷贝的数据长度

void *memcpy(>const void *src,size_t count );

2. 把buffer所指内存区域的前count个字节设置成字符c.说明:返回指向buffer的指针。


void *memset ( void  *dest,  int         c         ,size_tcount );


3. srcdest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串


char        *strcpy      ( char                  *strDestination,const char                 *strSource);
wchar_t *wcscpy ( wchar_t *strDestination,const wchar_t *strSource);
unsigned char *_mbscpy( unsigned char *strDestination, constunsigned char *strSource );

4. 把src所指示的以'\0'结尾的字符串的前n个字节复制到dest所指的数组中。复制时连同字符串的'\0'一起被复制。


char           *strncpy      (char                    *strDest,const char                  *strSource,size_t count );
wchar_t *wcsncpy ( wchar_t *strDest,const wchar_t *strSource,size_t count );
unsigned char *_mbsncpy (unsigned char *strDest,const unsigned char *strSource,size_t count );

 STRING.H 

#ifdef  _M_MRX000
_CRTIMP void * __cdecl memcpy(void *, const void *, size_t);
_CRTIMP int __cdecl memcmp(const void *, const void *, size_t);
_CRTIMP void * __cdecl memset(void *, int, size_t);
_CRTIMP char * __cdecl _strset(char *, int);
_CRTIMP char * __cdecl strcpy(char *, const char *);
_CRTIMP char * __cdecl strcat(char *, const char *);
_CRTIMP int __cdecl strcmp(const char *, const char *);
_CRTIMP size_t __cdecl strlen(const char *);
#else
void * __cdecl memcpy(void *, const void *, size_t);
int __cdecl memcmp(const void *, const void *, size_t);
void * __cdecl memset(void *, int, size_t);
char * __cdecl _strset(char *, int);
char * __cdecl strcpy(char *, const char *);
char * __cdecl strcat(char *, const char *);
int __cdecl strcmp(const char *, const char *);
size_t __cdecl strlen(const char *);
#endif

举报

相关推荐

0 条评论