C跟C++mem函数的类型及用法
2017-05-08 14:52
211 查看
函数名称: memccpy
函数原型: void *memccpy(void *dest, const void *src, int c, size_t n)
函数功能: 字符串拷贝,到指定长度或遇到指定字符时停止拷贝
函数返回:
参数说明: src-源字符串指针,c-中止拷贝检查字符,n-长度,dest-拷贝底目的字符串指针
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
int main()
{
char *src= "This is the source string ";
char dest[50];
char *ptr;
ptr=memccpy(dest,src, 'c ',strlen(src));
if (ptr)
{
*ptr= '\0 ';
printf( "The character was found:%s ",dest);
}
else
printf( "The character wasn 't found ");
return 0;
}
@函数名称: memchr
函数原型: void *memchr(const void *s, int c, size_t n)
函数功能: 在字符串中第开始n个字符中寻找某个字符c的位置
函数返回: 返回c的位置指针,返回NULL时表示未找到
参数说明: s-要搜索的字符串,c-要寻找的字符,n-指定长度
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
int main()
{
char str[17];
char *ptr;
strcpy(str, "This is a string ");
ptr=memchr(str, 'r ',strlen(str));
if(ptr)
printf( "The character 'r ' is at position:%d ",ptr-str);
else
printf( "The character was not found ");
return 0;
}
@函数名称: memcmp
函数原型: int memcmp(const void *s1, const void *s2, size_t n)
函数功能: 按字典顺序对字符串s1,s2比较,并只比较前n个字符
函数返回: 返回数值表示比较结果
参数说明: s1,s2-要比较的字符串,n-比较的长度
所属文件: <string.h>,<mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
auto char buffer[80];
strcpy(buffer, "world ");
if( memcmp(buffer, "would ",6)<0){
printf( "Less than\n ");
}
return 0;
}
@函数名称: memicmp
函数原型: int memicmp(const void *s1, const void *s2, size_t n)
函数功能: 按字典顺序、不考虑字母大小写对字符串s1,s2比较,并只比较前n个字符
函数返回: 返回数值表示比较结果
参数说明: s1,s2-要比较的字符串,n-比较的长度
所属文件: <string.h>,<mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *buf1 = "ABCDE123 ";
char *buf2 = "abcde456 ";
int stat;
stat = memicmp(buf1, buf2, 5);
printf( "The strings to position 5 are ");
if(stat)
printf( "not ");
printf( "the same ");
return 0;
}
@函数名称: memcpy
函数原型: void *memcpy(void *dest, const void *src, size_t n)
函数功能: 字符串拷贝
函数返回: 指向dest的指针
参数说明: src-源字符串,n-拷贝的最大长度
所属文件: <string.h>,<mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
char src[] = "****************************** ";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709 ";
char *ptr;
printf( "destination before memcpy: %s ",dest);
ptr=memcpy(dest,src,strlen(src));
if(ptr)
printf( "destination after memcpy:%s ",dest);
else
printf( "memcpy failed ");
return 0;
}
@函数名称: memmove
函数原型: void *memmove(void *dest, const void *src, size_t n)
函数功能: 字符串拷贝
函数返回: 指向dest的指针
参数说明: src-源字符串,n-拷贝的最大长度
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
int main()
{
char dest[40]= "abcdefghijklmnopqrstuvwxyz0123456789 ";
printf( "destination prior to memmove:%s\n ",dest);
memmove(dest+1,dest,35);
printf( "destination after memmove:%s ",dest);
return 0;
}
@函数名称: memset
函数原型: void *memset(void *s, int c, size_t n)
函数功能: 字符串中的n个字节内容设置为c
函数返回:
参数说明: s-要设置的字符串,c-设置的内容,n-长度
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
#include <mem.h>
int main()
{
char buffer[] = "Hello world ";
printf( "Buffer before memset:%s ",buffer);
memset(buffer, '* ',strlen(buffer)-1);
printf( "Buffer after memset:%s ",buffer);
return 0;
}
函数原型: void *memccpy(void *dest, const void *src, int c, size_t n)
函数功能: 字符串拷贝,到指定长度或遇到指定字符时停止拷贝
函数返回:
参数说明: src-源字符串指针,c-中止拷贝检查字符,n-长度,dest-拷贝底目的字符串指针
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
int main()
{
char *src= "This is the source string ";
char dest[50];
char *ptr;
ptr=memccpy(dest,src, 'c ',strlen(src));
if (ptr)
{
*ptr= '\0 ';
printf( "The character was found:%s ",dest);
}
else
printf( "The character wasn 't found ");
return 0;
}
@函数名称: memchr
函数原型: void *memchr(const void *s, int c, size_t n)
函数功能: 在字符串中第开始n个字符中寻找某个字符c的位置
函数返回: 返回c的位置指针,返回NULL时表示未找到
参数说明: s-要搜索的字符串,c-要寻找的字符,n-指定长度
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
int main()
{
char str[17];
char *ptr;
strcpy(str, "This is a string ");
ptr=memchr(str, 'r ',strlen(str));
if(ptr)
printf( "The character 'r ' is at position:%d ",ptr-str);
else
printf( "The character was not found ");
return 0;
}
@函数名称: memcmp
函数原型: int memcmp(const void *s1, const void *s2, size_t n)
函数功能: 按字典顺序对字符串s1,s2比较,并只比较前n个字符
函数返回: 返回数值表示比较结果
参数说明: s1,s2-要比较的字符串,n-比较的长度
所属文件: <string.h>,<mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
auto char buffer[80];
strcpy(buffer, "world ");
if( memcmp(buffer, "would ",6)<0){
printf( "Less than\n ");
}
return 0;
}
@函数名称: memicmp
函数原型: int memicmp(const void *s1, const void *s2, size_t n)
函数功能: 按字典顺序、不考虑字母大小写对字符串s1,s2比较,并只比较前n个字符
函数返回: 返回数值表示比较结果
参数说明: s1,s2-要比较的字符串,n-比较的长度
所属文件: <string.h>,<mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *buf1 = "ABCDE123 ";
char *buf2 = "abcde456 ";
int stat;
stat = memicmp(buf1, buf2, 5);
printf( "The strings to position 5 are ");
if(stat)
printf( "not ");
printf( "the same ");
return 0;
}
@函数名称: memcpy
函数原型: void *memcpy(void *dest, const void *src, size_t n)
函数功能: 字符串拷贝
函数返回: 指向dest的指针
参数说明: src-源字符串,n-拷贝的最大长度
所属文件: <string.h>,<mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
char src[] = "****************************** ";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709 ";
char *ptr;
printf( "destination before memcpy: %s ",dest);
ptr=memcpy(dest,src,strlen(src));
if(ptr)
printf( "destination after memcpy:%s ",dest);
else
printf( "memcpy failed ");
return 0;
}
@函数名称: memmove
函数原型: void *memmove(void *dest, const void *src, size_t n)
函数功能: 字符串拷贝
函数返回: 指向dest的指针
参数说明: src-源字符串,n-拷贝的最大长度
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
int main()
{
char dest[40]= "abcdefghijklmnopqrstuvwxyz0123456789 ";
printf( "destination prior to memmove:%s\n ",dest);
memmove(dest+1,dest,35);
printf( "destination after memmove:%s ",dest);
return 0;
}
@函数名称: memset
函数原型: void *memset(void *s, int c, size_t n)
函数功能: 字符串中的n个字节内容设置为c
函数返回:
参数说明: s-要设置的字符串,c-设置的内容,n-长度
所属文件: <string.h>,<mem.h>
#include <string.h>
#include <stdio.h>
#include <mem.h>
int main()
{
char buffer[] = "Hello world ";
printf( "Buffer before memset:%s ",buffer);
memset(buffer, '* ',strlen(buffer)-1);
printf( "Buffer after memset:%s ",buffer);
return 0;
}
相关文章推荐
- 明确C++风格的类型转换的用法
- C++变长参数函数的用法(转载)
- C++ 操作符重载、函数对象及类类型转换
- 混沌 In C++::是类型?还是函数调用?
- C#中调用C++的dll的参数为指针类型的导出函数
- 混沌 In C++::是类型?还是函数调用?
- C++风格的类型转换的用法
- 时间类型的转换,SQL中CONVERT转化函数的用法
- C++箴言:用成员函数模板接受兼容类型
- C++ enum类型的一个更好的用法
- C++中函数中参数和返回值都是用户定义类型(这里主要是类的情况时的分析)
- 时间类型的转换,SQL中CONVERT转化函数的用法
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- c++ map 类型用法
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 从C/C++迁移到PHP――判断字符类型的函数
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 时间类型的转换,SQL中CONVERT转化函数的用法 (转载)
- 理解 《混沌 In C++::是类型?还是函数调用?》