The <string.h> Header File

ANSI-compatible string manipulation routines

Functions

_memset
Sets num bytes of buffer to byte c.
cmpstri
Performs case-insensitive string comparison.
memchr
Searches the first len bytes of array str for character c.
memcmp
Compares two blocks of signed chars.
memcpy
Copies a block of len bytes from src to dest.
memmove
Copies a block of len bytes from src to dest, with possibility of overlaping of source and destination block.
memset
Sets num bytes of buffer to byte c.
memucmp
Compares two blocks of unsigned chars.
sprintf
Sends formatted output to a string.
strcat
Appends src to dest.
strchr
Finds c in str.
strcmp
Compares one string to another.
strcpy
Copies string src to dest.
strcspn
Scans a string.
strerror
Gives an error message string.
stricmp
Performs case-insensitive string comparison.
strlen
Calculates length of a string.
strncat
Appends at most maxlen characters of src to dest.
strncmp
Compares at most maxlen characters of one string to another.
strncpy
Copies at most maxlen characters of src to dest.
strpbrk
Scans one string for the first occurrence of any character that's in a second string.
strrchr
Finds the last occurrence of c in str.
strspn
Scans a string for a segment that is a subset of a set of characters.
strstr
Finds the first occurrence of a substring in another string.
strtok
Scans s1 for the first token not contained in s2.

Constants

NULL
A null-pointer value.

Predefined Types

size_t
A type to define sizes of strings and memory blocks.

cmpstri

short cmpstri (const unsigned char *s1, const unsigned char *s2);

Performs case-insensitive string comparison.

cmpstri acts like strcmp, but the comparison is case-insensitive. More precisely, it internally converts all uppercase characters to lowercase (unlike stricmp, which converts all lowercase characters to uppercase).

See also: stricmp, strcmp


strcat

char *strcat (char *dest, const char *src);

Appends src to dest.

strcat appends a copy of src to the end of dest, overwriting the null character terminating the string pointed to by dest. The length of the resulting string is strlen(dest) + strlen(src). strcat returns a pointer to the concatenated strings (this is dest, in fact).

Note: This routine assumes that dest points to a buffer large enough to hold the concatenated string.


strchr

char *strchr (const char *str, short c);

Finds c in str.

strchr scans a string in the forward direction, looking for a specific character. strchr finds the first occurrence of the character c in the string str. The null-terminator is considered to be part of the string, so that, for example,

strchr (s, 0)

returns a pointer to the terminating null character of the string s. Returns a pointer to the first occurrence of the character c in str. If c does not occur in str, strchr returns NULL.


strcmp

short strcmp (const unsigned char *s1, const unsigned char *s2);

Compares one string to another.

strcmp performs an unsigned comparison of s1 to s2. It starts with the first character in each string and continues with subsequent characters until the corresponding characters differ or until the end of the strings is reached. strcmp returns a value that is

More precisely, if the strings differ, the value of the first nonmatching character in s2 subtracted from the corresponding character in s1 is returned.

Note: This routine is declared as "short" although the ANSI standard proposes "long". This is important, because TIOS the strncmp routine puts garbage in the higher half of the d0 register.

See also: strncmp, cmpstri, stricmp


strcpy

char *strcpy (char *dest, const char *src);

Copies string src to dest.

strcpy copies string src to dest, stopping after the terminating null character has been moved. Returns dest.

Note: If the objects pointed to by src and dest overlap in memory, the behavior is undefined. strcpy assumes that src points to a buffer large enough to hold dest.


strcspn

unsigned long strcspn (const char *s1, const char *s2);

Scans a string.

strcspn returns the length of the initial segment of string s1 that consists entirely of characters not from string s2. If string s1 contains no characters from string s2, strcspn returns the length of string s1.


strerror

char *strerror (short err_no);

Gives an error message string.

strerror returns a pointer to string which contains text of the system error message err_no. Note that this is not a TI-Basic error message, but a low level error message. Here is a complete table of such messages:

0no error
1no such file entry
2I/O error
3not a serial device
4out of memory
5permission denied
6block device required
7no such device
8invalid argument
9file table is full
10device directory is full
11no space left on device
12no more allocation blocks
13no more data blocks on device
14file is open
15no RAM space configured
16no heap space configured
17seek can't extend read only file
18bad file descriptor - file not open
19invalid signal number
20argument out of range
21result out of range

Other values of err_no will generate "undefined errno value" message.

Note: Previous releases of TIGCCLIB prior to 2.0 reports wrongly that err_no is a TI-Basic error code, which is not true. To get a pointer to TI-Basic error message, use find_error_message function.


stricmp

AMS 2.00 or higher

short stricmp (const unsigned char *s1, const unsigned char *s1);

Performs case-insensitive string comparison.

stricmp acts like strcmp, but the comparison is case-insensitive. More precisely, it internally converts all lowercase characters to uppercase (unlike cmpstri, which converts all uppercase characters to lowercase).

Note: This function is buggy in the AMS versions 2.00 through 2.03: If s1 contains characters above 127 (i.e. extended/international characters), and these characters are really needed for the comparison, it always returns a negative value. So, if you really need to use this function, make sure that you never call it with such characters in s1.

See also: cmpstri, strcmp


strlen

unsigned long strlen (const char *str);

Calculates length of a string.

strlen calculates the length of str. Returns the number of characters in str, not counting the terminating null character.


strncat

char *strncat (char *dest, const char *src, unsigned long maxlen);

Appends at most maxlen characters of src to dest.

strncat copies at most maxlen characters of src to the end of dest and then appends a null character. The null character terminating src is overwritten by the first character in dest. The maximum length of the resulting string is strlen(dest) + maxlen. strncat returns dest.

Note: This routine assumes that src points to a buffer large enough to hold the concatenated string. Since strncat appends a null character to the result, it may add maxlen+1 characters to the string.


strncmp

short strncmp (const unsigned char *s1, const unsigned char *s2, unsigned long maxlen);

Compares at most maxlen characters of one string to another.

strncmp makes the same unsigned comparison as strcmp, but looks at no more than maxlen characters. It starts with the first character in each string and continues with subsequent characters until the corresponding characters differ or until it has examined maxlen characters. strncmp returns an int value based on the result of comparing s1 (or part of it) to s2 (or part of it):

More precisely, if the strings differ, the value of the first nonmatching character in s2 subtracted from the corresponding character in s1 is returned. The subtraction casts the input strings to unsigned chars so that the characters in the range 128..255 are considered above the characters in the range 0..127.

Note: This routine is declared as "short" although the ANSI standard proposes "long". This is important, because TIOS the strncmp routine puts garbage in the higher half of the d0 register.

See also: strcmp


strncpy

char *strncpy (char *dest, const char *src, unsigned long maxlen);

Copies at most maxlen characters of src to dest.

strncpy copies up to maxlen characters from src into dest, truncating or null-padding dest. The target string, dest, might not be null-terminated if the length of src is maxlen or more. Returns dest.

Note: If the objects pointed to by src and dest overlap in memory, the behavior is undefined. strcpy assumes that src points to a buffer large enough to hold maxlen characters.


strpbrk

char *strpbrk (const char *s1, const char *s2);

Scans one string for the first occurrence of any character that's in a second string.

strpbrk scans a string, s1, for the first occurrence of any character appearing in s2. strpbrk returns a pointer to the first occurrence of any of the characters in s2. If none of the s2 characters occurs in s1, it returns NULL.


strrchr

char *strrchr (const char *str, short c);

Finds the last occurrence of c in str.

strrchr scans a string in the reverse direction, looking for a specific character. strrchr finds the last occurrence of the character c in the string str. The null-terminator is considered to be part of the string. strrchr returns a pointer to the last occurrence of the character c. If c does not occur in str, strrchr returns NULL.


strspn

unsigned long strspn (const char *s1, const char *s2);

Scans a string for a segment that is a subset of a set of characters.

strspn finds the initial segment of string s1 that consists entirely of characters from string s2. Returns the length of the initial segment of s1 that consists of characters entirely from s2. If s1 contains no characters from s2, NULL is returned.


strstr

char *strstr (const char *str, const char *substr);

Finds the first occurrence of a substring in another string.

strstr scans str for the first occurrence of the substring substr. strstr returns a pointer to the element in str where substr begins (points to substr in str). If substr does not occur in str, strstr returns NULL.


strtok

char *strtok (char *s1, const char *s2);

Scans s1 for the first token not contained in s2.

strtok considers the string s1 to consist of a sequence of zero or more text tokens, separated by spans of one or more characters from the separator string s2. The first call to strtok returns a pointer to the first character of the first token in s1 and writes a null character into s1 immediately following the returned token. Subsequent calls with NULL for the first argument will work through the string s1 in this way, until no tokens remain. The separator string, s2, can be different from call to call. strtok returns a pointer to the token found in s1. A null pointer is returned when there are no more tokens.


Return to the main index