|
|
bcmp(比较内存内容) |
|
相关函数 |
bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp |
|
表头文件 |
#include<string.h> |
|
定义函数 |
int bcmp ( const void *s1,const void * s2,int n); |
|
函数说明 |
bcmp()用来比较s1和s2所指的内存区间前n个字节,若参数n为0,则返回0。 |
|
返回值 |
若参数s1 和s2 所指的内存内容都完全相同则返回0 值,否则返回非零值。 |
|
附加说明 |
建议使用memcmp()取代。 |
|
范例 |
参考memcmp()。 |
|
|
bcopy(拷贝内存内容) |
|
相关函数 |
memccpy,memcpy,memmove,strcpy,ctrncpy |
|
表头文件 |
#include <string.h> |
|
定义函数 |
void bcopy ( const void *src,void *dest ,int n); |
|
函数说明 |
bcopy()与memcpy()一样都是用来拷贝src所指的内存内容前n个字节到dest所指的地址,不过参数src与dest在传给函数时是相反的位置。 |
|
返回值 |
|
|
附加说明 |
建议使用memcpy()取代 |
|
范例 |
#include<string.h> main() { char dest[30]=”string(a)”; char src[30]=”string\0string”; int i; bcopy(src,dest,30);/* src指针放在前*/ printf(bcopy(): “) for(i=0;i<30;i++) printf(“%c”,dest[i]); memcpy(dest src,30); /*dest指针放在钱*/ printf(‘\nmemcpy() : “); for(i=0;i<30;i++) printf(“%c”,dest[i]); |
|
执行 |
bcopy() : string string memcpy() :string sring |
|
|
bzero(将一段内存内容全清为零) |
|
相关函数 |
memset,swab |
|
表头文件 |
#include<string.h> |
|
定义函数 |
void bzero(void *s,int n); |
|
函数说明 |
bzero()会将参数s所指的内存区域前n个字节,全部设为零值。相当于调用memset((void*)s,0,size_tn); |
|
返回值 |
|
|
附加说明 |
建议使用memset取代 |
|
范例 |
参考memset()。 |
|
|
index(查找字符串中第一个出现的指定字符) |
|
相关函数 |
rindex,srechr,strrchr |
|
表头文件 |
#include<string.h> |
|
定义函数 |
char * index( const char *s, int c); |
|
函数说明 |
index()用来找出参数s字符串中第一个出现的参数c地址,然后将该字符出现的地址返回。字符串结束字符(null)也视为字符串一部分。 |
|
返回值 |
如果找到指定的字符则返回该字符所在地址,否则返回0。 |
|
范例 |
#include<string.h> main() { char *s =”0123456789012345678901234567890”; char *p; p =index(s,’5’); printf(%s\n”,p); } |
|
执行 |
5.68e+25 |
|
|
memccpy(拷贝内存内容) |
|
相关函数 |
bcopy,memcpy,memmove,strcpy,strncpy |
|
表头文件 |
#include<string.h> |
|
定义函数 |
void * memccpy(void *dest, const void * src, int c,size_t n); |
|
函数说明 |
memccpy()用来拷贝src所指的内存内容前n个字节到dest所指的地址上。与memcpy()不同的是,memccpy()会在复制时检查参数c是否出现,若是则返回dest中值为c的下一个字节地址。 |
|
返回值 |
返回指向dest中值为c的下一个字节指针。返回值为0表示在src所指内存前n个字节中没有值为c的字节。 |
|
范例 |
#include<string.h> main() { char a[]="string[a]"; char b[]="string(b)"; memccpy(a,b,'b',sizeof(b)); printf("memccpy():%s\n",a); } |
|
执行 |
memccpy():string(b) |
|
|
memchr(在某一内存范围中查找一特定字符) |
|
相关函数 |
index,rindex,strchr,strpbrk,strrchr,strsep,strspn,strstr |
|
表头文件 |
#include<string.h> |
|
定义函数 |
void * memchr(const void *s,int c,size_t n); |
|
函数说明 |
memchr()从头开始搜寻s所指的内存内容前n个字节,直到发现第一个值为c的字节,则返回指向该字节的指针。
本文关键:Linux C 函数参考(内存及字符串操作)
相关方案
|