strings.h File Reference

Typedef size_t

typedef __size_t size_t

_SIZE_T_DECLARED

bcmp ( const void *, const void *, size_t )

IMPORT_C intbcmp(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.

Examples:
#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()

Return Value
bcmp function returns 0 if the byte sequences are equal and non-zero otherwise.

bcopy ( const void *, void *, size_t )

IMPORT_C voidbcopy(const void *,
void *,
size_t
)
Examples:
#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

See also: memccpy() memcpy() memmove() strcpy()

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.

bzero ( void *, size_t )

IMPORT_C voidbzero(void *,
size_t
)
Examples:
#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

See also: memset() swab()

Parameters
The bzero function writes len zero bytes to the string b. If len is zero, bzero does nothing.

ffs ( int )

IMPORT_C intffs(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.

Examples:
#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()

index ( const char *, int )

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.

Examples:
#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()
Return Value
The functions index and rindex return a pointer to the located character, or NULL if the character does not appear in the string.

rindex ( const char *, int )

IMPORT_C char *rindex(const char *,
int
)
Parameters
Refer to index() for the documentation

strcasecmp ( const char *, const char * )

IMPORT_C intstrcasecmp(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.

Examples:
#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()
Return Value
The strcasecmp and strncasecmp return an integer greater than, equal to, or less than 0, according to whether s1 is lexicographically greater than, equal to, or less than s2 after translation of each corresponding character to lower-case. The strings themselves are not modified.

strncasecmp ( const char *, const char *, size_t )

IMPORT_C intstrncasecmp(const char *,
const char *,
size_t
)
Parameters
Refer to strcasecmp() for the documentation