C语言标准库 经常使用函数说明

void *memset(void *str, int c, size_t n)

Syntaxapp

  void *memset(void *str, int c, size_t n)less

Description:this

    The C library function void *memset(void *str, int c, size_t n) copies the character c (an unsigned char) to the first n characters of the    string pointed to, by the argument str.spa

Parameters:指针

  • str -- This is a pointer to the block of memory to fill.
  • c -- This is the value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
  • n -- This is the number of bytes to be set to the value.

Return Value:orm

  This function returns a pointer to the memory area str.htm

 

void *memchr(const void *str, int c, size_t n)

Descriptionip

    The C library function void *memchr(const void *str, int c, size_t n) searches for the first occurrence of the character c (an unsigned   char) in the first n bytes of the string pointed to, by the argument str.内存

Parametersget

  • str -- This is the pointer to the block of memory where the search is performed.

  • c -- This is the value to be passed as an int, but the function performs a byte per byte search using the unsigned char conversion of this value.

  • n -- This is the number of bytes to be analyzed.

Return Value

This function returns a pointer to the matching byte or NULL if the character does not occur in the given memory area.

从buf所指内存区域的前count个字节查找字符ch。当第一次遇到字符ch时中止查找。若是成功,返回指向字符ch的指针;不然返回NULL。

 

int memcmp(const void *str1, const void *str2, size_t n)

Description

    The C library function int memcmp(const void *str1, const void *str2, size_t n)) compares the first n bytes of memory area str1 and   memory area str2.

Parameters

  • str1 -- This is the pointer to a block of memory.

  • str2 -- This is the pointer to a block of memory.

  • n -- This is the number of bytes to be compared.

Return Value

  • if Return value < 0 then it indicates str1 is less than str2.

  • if Return value > 0 then it indicates str2 is less than str1.

  • if Return value = 0 then it indicates str1 is equal to str2.

 

void *memmove(void *str1, const void *str2, size_t n)

Description

    The C library function void *memmove(void *str1, const void *str2, size_t n) copies n characters from str2 to str1, but for       overlapping memory blocks, memmove() is a safer approach than memcpy().

Declaration

  Following is the declaration for memmove() function.

Parameters

  • str1 -- This is a pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.

  • str2 -- This is a pointer to the source of data to be copied, type-casted to a pointer of type void*.

  • n -- This is the number of bytes to be copied.

Return Value

This function returns a pointer to the destination, which is str1.