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 * *
}