C Standard Library__library

Source: Internet
Author: User
Tags strcmp

C Standard Library

Strchr

Purpose:

Searches a string for a given character, which may

The null character '/0 '.

Entry:

Char *string-string to search in

Char C-character to search for

Exit:

Returns pointer to the ' the ' of C in string

Returns NULL if C does not occur in string

Char *STRCHR (

const char * string,

int CH

)

{

while (*string && *string!= (char) ch)

string++;

if (*string = = (char) ch)

Return ((char *) string);

return (NULL);

}

Strlen

Purpose:

Finds the length in bytes of the given string, not

Including the final null character.

Entry:

const char * str-string whose length is to be computed

Exit:

Length of the string "str", exclusive of the final null

Byte

size_t strlen (

const char * str

)

{

const char *eos = str;

while (*eos++);

return ((int) (eos-str-1));

}

strcpy

Purpose:

Copies the string src into the spot specified by

Dest Assumes enough room.

Entry:

char * dst-string over which ' src ' is ' to ' copied

const char * src-string to is copied over "DST"

Exit:

The address of "DST"

Char *strcpy (char * DST, const char * src)

{

char * cp = DST;

while (*cp++ = *src++)

; /* Copy src over DST * *

return (DST);

}

strcmp

Purpose:

STRCMP compares two strings and returns an integer

To indicate whether the less than the second,

The two are equal, or whether the ' the ' is greater than

The second.

Comparison is doing byte by byte on a UNSIGNED basis,

Which is to say so Null (0) is less than no other

Character (1-255).

Entry:

const char * src-string for left-hand side of comparison

const char * dst-string for right-hand side of comparison

Exit:

returns-1 if SRC < DST

returns 0 if src = DST

Returns +1 if src > DST

int strcmp (

const char * src,

const char * DST

)

{

int ret = 0;

while (! (ret = * (unsigned char *) src-* (unsigned char *) DST) && *DST)

++SRC, ++DST;

if (Ret < 0)

ret =-1;

else if (Ret > 0)

ret = 1;

return (ret);

}

Strcat

Purpose:

Concatenates src onto the end of Dest. Assumes enough

Spaces in Dest.

Entry:

Char *dst-string to which ' src ' is ' to ' appended

const char *src-string to is appended to "end of"

"DST"

Exit:

The address of "DST"

char * __cdecl strcat (

char * DST,

const char * src

)

{

char * cp = DST;

while (*CP)

cp++; /* Find end of DST * *

while (*cp++ = *src++); /* Copy src to end of DST * *

return (DST); /* RETURN DST * *

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.