typedef __size_t | size_t |
IMPORT_C int | bcmp | ( | const void * | , |
const void * | , | |||
size_t | ||||
) |
The bcmp function compares byte string b1 against byte string b2, returning zero if they are identical and non-zero otherwise. Both strings are assumed to be length bytes long. Zero-length strings are always identical.
The strings may overlap.
#include <string.h> #include <stdio.h> int main() { int ret = 0; ret = bcmp("a","a",1); printf("bcmp(\"a\",\"a\",1) is %d",ret); ret = bcmp("abcd","abce",4); printf(" bcmp(\"abcd\",\"abce\",1) is %d",ret); ret = bcmp("abc","xyz",0); printf(" bcmp(\"abc\",\"xyz\",0) is %d",ret); return 0; }Output
bcmp("a","a",1) is 0 bcmp("abcd","abce",1) is -1 bcmp("abc","xyz",0) is 0
See also: memcmp() strcasecmp() strcmp() strcoll() strxfrm()
IMPORT_C void | bcopy | ( | const void * | , |
void * | , | |||
size_t | ||||
) |
#include <string.h> #include <stdio.h> int main() { char dst[50]; bcopy("Hello World",dst,12); printf("Destination string after bcopy = %s ",dst); return 0; }Output
Destination string after bcopy = Hello World
Parameters | |
---|---|
The bcopy function copies length bytes from string src0 to string dst0 . The two strings may overlap. If length is zero no bytes are copied. |
IMPORT_C void | bzero | ( | void * | , |
size_t | ||||
) |
#include <string.h> #include <stdio.h> int main() { char dst[50] = "abcdef"; bzero(dst + 2, 2); if(!strcmp(dst, "ab")) printf("dst = %s ",dst); if(!strcmp(dst+3, "")) printf("zeros added to dst string "); if(!strcmp(dst + 4, "ef")) printf("dst + 4 = %s ",dst); return 0; }Output
dst = ab zeros added to dst string dst + 4 = ab
Parameters | |
---|---|
The bzero function writes len zero bytes to the string b. If len is zero, bzero does nothing. |
IMPORT_C int | ffs | ( | int | ) |
The ffs and ffsl functions find the first bit set in mask and return the index of that bit.
The fls and flsl functions find the last bit set in mask and return the index of that bit.
Bits are numbered starting from 1, starting at the right-most (least significant) bit. A return value of zero from any of these functions means that the argument was zero.
#include <string.h> #include <stdio.h> int main() { int i = 0x10; int j = ffs(i); if(j == 5) printf("First bit position in 0x10 is %d ",j); return 0; }Output
First bit position in 0x10 is 5
Parameters | |
---|---|
Note: This description also covers the following functions - ffsl() fls() flsl() |
IMPORT_C char * | index | ( | const char * | , |
int | ||||
) |
The index function locates the first occurrence of ch (converted to a char ) in the string pointed to by p. The terminating null character is considered part of the string; therefore if ch is \0, the functions locate the terminating \0.
The rindex function is identical to index, except it locates the last occurrence of ch.
#include <string.h> #include <stdio.h> int main() { char one[50]; char* ret; strcpy(one,"abcd"); ret = index(one, c); if(!strncmp(one+2,ret,1)) printf("index of \ c\ in string \"abcd\" is %d \n",2); ret = index(one, z); if(ret == NULL) printf("\ z\ not found in string \"abcd\"\n"); ret = index(one, \0); if(!strncmp(one+4,ret,1)) printf("index of \ \ \0\ in string \"abcd\" is %d\n",4); strcpy(one,"cdcab"); ret = rindex(one, c); if(!strncmp(one+2,ret,1)) printf("rindex of \ c\ in string \"cscab\" is %d\n",2); strcpy(one,"dcab"); ret = rindex(one, \0); if(!strncmp(one+4,ret,1)) printf("index of \ \ \0\ in string \"dcab\" is %d\n",4); return 0; }Output
index of c in string "abcd" is 2 z not found in string "abcd" index of \0 in string "abcd" is 4 rindex of c in string "cscab" is 2 index of \0 in string "dcab" is 4
See also: memchr() strchr() strcspn() strpbrk() strsep() strspn() strstr() strtok()
Parameters | |
---|---|
Note: This description also covers the following functions - rindex() |
IMPORT_C int | strcasecmp | ( | const char * | , |
const char * | ||||
) |
The strcasecmp and strncasecmp functions compare the null-terminated strings s1 and s2. The strcasecmp() function compares the two strings s1 and s2 , ignoring the case of the characters.
The strncasecmp compares at most len characters.
#include <string.h> #include <stdio.h> int main() { int ret; ret = strcasecmp("ABC","abc"); printf("strcasecmp of \"ABC\" \"abc\" is %d ",ret); ret = strcasecmp("abc","abc"); printf("strcasecmp of \"abc\" \"abc\" is %d ",ret); return 0; }Output
strcasecmp of "ABC" "abc" is 0 strcasecmp of "abc" "abc" is 0
See also: bcmp() memcmp() strcmp() strcoll() strxfrm() tolower()
Parameters | |
---|---|
Note: This description also covers the following functions - strncasecmp() |