==========
STRING.H
==========
Functions
=========
_fmemccpy
_fmemchr
_fmemcmp
_fmemcpy
_fmemicmp
_fmemset
_fstrcat
_fstrchr
_fstrcmp
_fstrcpy
_fstrcspn
_fstrdup
_fstricmp
_fstrlen
_fstrlwr
_fstrncat
_fstrncmp
_fstrnicmp
_fstrncpy
_fstrnset
_fstrpbrk
_fstrrchr
_fstrrev
_fstrset
_fstrspn
_fstrstr
_fstrtok
_fstrupr
memccpy
memchr
memcmp
memcpy
memicmp
memmove
memset
movedata
movmem
setmem
stpcpy
strcat
strchr
strcmp
strcmpi
strcpy
strcspn
strdup
_strerror
strerror
stricmp
strlen
strlwr
strncat
strncmp
strncmpi
strncpy
strnicmp
strnset
strpbrk
strrchr
strrev
strset
strspn
strstr
strtok
strxfrm
strupr
Constants, data types, and global variables
===========================================
size_t
See Also
========
List of all Header files
=======
MEM.H
=======
Functions
=========
_fmemccpy
_fmemchr
_fmemcmp
_fmemcpy
_fmemicmp
_fmemmove
_fmemset
_fmovmem
_fsetmem
memccpy
memchr
memcmp
memcpy
memicmp
memmove
memset
movedata
movmem
setmem
Constants, data types, and global variables
============================================
NULL
ptrdiff_t
size_t
See Also
========
List of all Header files
========
stpcpy <STRING.H>
========
Copies one string into another
Declaration: char *stpcpy(char *dest, const char *src);
Remarks:
stpcpy copies the string src to dest,
stopping after the terminating null character
of src has been reached.
Return Value: dest + strlen(src)
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | Yes | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s\n", string);
return 0;
}
===========
_fstrcat,
strcat <STRING.H>
===========
Appends one string to another
Declaration:
* char *strcat(char *dest, const char *src);
* char far * far _fstrcat(char far *dest, const char far *src);
Remarks:
strcat appends a copy of src to the end of
dest. The length of the resulting string is
strlen(dest) + strlen(src).
_fstrcat is the far version.
Return Value:
strcat returns a pointer to the concatenated
strings.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strcat | Yes | Yes | Yes | Yes | |
_fstrcat | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *turbo = "Turbo";
strcpy(destination, turbo);
strcat(destination, blank);
strcat(destination, c);
printf("%s\n", destination);
return 0;
}
===========
_fstrchr, <STRING.H>
strchr
===========
Scans a string for the first occurence of a given character
Declaration:
* char *strchr(const char *s, int c);
* char far * far _fstrchr(const char far *s, int c);
Remarks:
strchr scans a string in the forward
direction, looking for a specific character.
_fstrchr is the far version.
These functions find the first occurrence of
the character c in the string s.
The null-terminator is considered to be part
of the string; for example,
strchr(strs, 0)
returns a pointer to the terminating null
character of the string strs.
Return Value:
* On success, returns a pointer to the
first occurrence of the character c in
string s.
* On error (if c does not occur in s),
returns null.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strchr | Yes | Yes | Yes | Yes | |
_fstrchr | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}
============================
_fstricmp, _fstrcmp, <STRING.H>
strcmp, strcmpi, stricmp
============================
* _fstrcmp and strcmp compare two strings
* strcmpi (a macro) compares two strings without case sensitivity
* _fstricmp and stricmp compare two strings without case sensitivity
Declaration:
* int strcmp(const char *s1, const char*s2);
* int strcmpi(const char *s1, const char *s2)
* int stricmp(const char *s1, const char *s2);
* int far _fstrcmp(const char far *s1, const char far *s2);
* int far _fstricmp(const char far *s1, const char far *s2);
Remarks:
* strcmp performs an unsigned comparison of
s1 to s2. _fstrcmp is the far version.
* strcmpi (implemented as a macro that calls
stricmp) performs an unsigned comparison of
s1 to s2, without case sensitivity.
* stricmp performs an unsigned comparison of
s1 to s2, without case sensitivity. _fstricmp
is the far version.
The string comparison 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.
To use strcmpi, you must include STRING.H.
This macro is provided for compatibility with
other C compilers.
Return Value:
These routines return an int value that is
* < 0 if s1 < s2
* == 0 if s1 == s2
* > 0 if s1 > s2
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strcmp | Yes | Yes | Yes | Yes | |
strcmpi | Yes | | Yes | | |
strnicmp | Yes | | Yes | | |
_fstrcmp | Yes | | Yes | | |
_fstrnicmp | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
_fstrncmp and _fstrnicmp
strncmp, strncmpi, and strnicmp
Examples:
strcmp example
strcmpi example
stricmp example
strcmp Example
================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");
ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");
return 0;
}
strcmpi Example
=================
/* strncmpi example */
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");
if (ptr == 0)
printf("buffer 2 equals buffer 1\n");
return 0;
}
stricmp Example
=================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = stricmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");
if (ptr == 0)
printf("buffer 2 equals buffer 1\n");
return 0;
}
=========
strcoll <STRING.H>
=========
Compares two strings
Declaration: int strcoll(char *s1, char *s2);
Remarks:
strcoll compares the string *s1 to the string
*s2, according to the collating sequence set
by setlocale.
Return Value:
strcoll returns a value that is
* < 0 if s1 < s2
* == 0 if s1 == s2
* > 0 i f s1 > s2
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | Yes | |
+-----+------+---------+--------+----------+
See Also:
strcmp
strcmpi
stricmp
strncmp
strncmpi
strnicmp
strxfrm
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *two = "International";
char *one = "Borland";
int check;
check = strcoll(one, two);
if (check == 0)
printf("The strings are equal\n");
if (check < 0)
printf("%s comes before %s\n", one, two);
if (check > 0)
printf("%s comes before %s\n", two, one);
return 0;
}
===========
_fstrcpy,
strcpy <STRING.H>
===========
Copies string src to dest
Declaration:
* char *strcpy(char *dest, const char *src);
* char far * _fstrcpy(char far *dest, const char far *src);
Remarks:
Copies string src to dest, stopping after the
terminating null character has been moved.
_fstrcpy is the far version.
Return Value: dest
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strcpy | Yes | Yes | Yes | Yes | |
_fstrcpy | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
strncpy
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strcpy(string, str1);
printf("%s\n", string);
return 0;
}
======================
_fstrcspn, _fstrspn, <STRING.H>
strcspn, strcspn
======================
* _fstrcspn and strcspn scan a string for a segment that DOES NOT contain
a subset of a set of characters
* _fstrspn and strspn scan a string for a segment that IS a subset of a
set of characters
Declaration:
* size_t strcspn(const char *s1, const char *s2);
* size_t strspn(const char *s1, const char *s2);
* size_t far _fstrcspn(const char *s1, const char far *s2);
* size_t far _fstrspn(const char far *s1, const char far *s2);
Remarks:
* strcspn and _fstrcspn find the initial
segment of string s1 that consists entirely
of characters NOT from string s2.
* strspn and _fstrspn find the initial
segment of string s1 that consists entirely
of characters from string s2.
Return Value:
* strcspn and _fstrcspn: the length of the
initial segment found (see Remarks).
* strspn and _fstrspn: the length of the
initial segment found (see Remarks).
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strcspn | Yes | Yes | Yes | Yes | |
_fstrcspn | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Examples:
strcspn example
strspn example
strspn example
================
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *string1 = "1234567890";
char *string2 = "123DC8";
int length;
length = strspn(string1, string2);
printf("Character where strings differ is at position %d\n", length);
return 0;
}
strcspn example
=================
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;
length = strcspn(string1, string2);
printf("Character where strings intersect is at position %d\n",
length);
return 0;
}
==================
strdup, _fstrdup <STRING.H>
==================
Copies a string into a newly created location
Declaration:
* char *strdup(const char *s);
* char far * far _fstrdup(const char far *s);
Remarks:
strdup makes a duplicate of string s,
obtaining space with a call to malloc.
_fstrdup is the far version.
The allocated space is (strlen(s) + 1) bytes
long.
You are responsible for freeing the space
allocated by strdup when it is no longer
needed.
Return Value:
* On success, returns a pointer to the
location containing the duplicated string
* On error (if space couldn't be allocated),
returns null
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strdup | Yes | Yes | Yes | | |
_fstrdup | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
free
Example:
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *dup_str, *string = "abcde";
dup_str = strdup(string);
printf("%s\n", dup_str);
free(dup_str);
return 0;
}
============
_strerror, <STRING.H>
strerror <STDIO.H, STRING.H>
============
* _strerror builds a customized error message
* strerror returns a pointer to an error message string
Declaration:
* char *_strerror(const char *s);
* char *strerror(int errnum);
Remarks:
* _strerror generates customized error
messages.
* strerror takes an error number and returns
a pointer to an error message string
associated with that error number.
With both functions, the error message string
is constructed in a static buffer that is
overwritten with each call to to function.
Customized Error Messages
=========================
With _strerror, if s is null, the return
value points to the most recently generated
error message.
If s is not null, the return value contains
the following:
* s (your customized error message)
* a colon
* a space
* the most-recently generated system error
message
* a new line.
The argument s should be =< 94 characters.
Return Value:
* _strerror returns a pointer to a null-
terminated string containing a
constructed error message.
* strerror returns a pointer to the error
message associated with errnum.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
_strerror | Yes | | Yes | | |
strerror | Yes | | Yes | Yes | |
+-----+------+---------+--------+----------+
See Also:
perror
Examples:
_strerror example
strerror example
_strerror example
===================
#include <stdio.h>
int main(void)
{
FILE *fp;
/* open a file for writing */
fp = fopen("TEST.$$$", "w");
/* force an error condition by attempting to read */
if (!fp) fgetc(fp);
if (ferror(fp))
/* display a custom error message */
printf("%s", _strerror("Custom"));
fclose(fp);
return 0;
}
strerror example
==================
#include <stdio.h>
#include <errno.h>
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s\n", buffer);
return 0;
}
============
_fstrlen,
strlen <STRING.H>
============
Calculates length of a string
Declaration:
* size_t strlen(const char *s);
* size_t far _fstrlen(const char far *s);
Remarks:
strlen calculates the length of s.
Return Value:
Returns the number of characters in s, not
counting the terminating null character.
_fstrlen is the far version.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strlen | Yes | Yes | Yes | Yes | |
_fstrlen | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "Borland International";
printf("%d\n", strlen(string));
return 0;
}
======================
_fstrlwr, _fstrupr,
strlwr, strupr <STRING.H>
======================
Converts s to all lowercase
Declaration:
* char *strlwr(char *s);
* char far * far _fstrlwr(char far *s);
* char *strupr(char *s);
* char far * far _fstrupr(char far *s);
Remarks:
* strlwr and _fstrlwr convert uppercase
letters (A to Z) in string s to lowercase
(a to z).
* strupr and _fstrupr convert lowercase
letters (a to z) in string s to uppercase
(A to Z).
No other characters are changed.
Return Value:
A pointer to the string s.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
tolower
toupper
Examples:
strlwr example
strupr example
strlwr example
================
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "Borland International";
printf("string prior to strlwr: %s\n", string);
strlwr(string);
printf("string after strlwr: %s\n", string);
return 0;
}
strupr example
================
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;
/* converts string to upper case characters */
ptr = strupr(string);
printf("%s\n", ptr);
return 0;
}
=============
_fstrncat,
strncat <STRING.H>
=============
Appends a portion of one string to another
Declaration:
* char *strncat(char *dest, const char *src, size_t maxlen);
* char far * far _fstrncat(char far *dest, const char far *src,
size_t maxlen);
Remarks:
strncat copies at most maxlen characters of
src to the end of dest and then appends a
null character.
_fstrncat is the far version.
The maximum length of the resulting string is
strlen(dest) + maxlen.
Return Value: dest
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strncat | Yes | Yes | Yes | Yes | |
_fstrncat | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *source = " States";
strcpy(destination, "United");
strncat(destination, source, 7);
printf("%s\n", destination);
return 0;
}
=================================
_fstrnicmp, _fstrncmp, strncmp, <STRING.H>
strncmpi, strnicmp
=================================
* _fstrncmp and strncmp compare portions of two strings
* strncmpi (a macro) compares portions of two strings,
without case sensitivity
* _fstrnicmp and strnicmp compare portions of two strings,
without case sensitivity
Declaration:
* int strncmp (const char *s1, const char *s2, size_t maxlen);
* int strncmpi(const char *s1, const char *s2, size_t maxlen);
* int strnicmp(const char *s1, const char *s2, size_t maxlen);
* int far _fstrncmp (const char far *s1, const char far *s2,
size_t maxlen);
* int far _fstrnicmp(const char far *s1, const char far *s2,
size_t maxlen);
Remarks:
Each of these routines compares s1 to s2,
looking at no more than maxlen characters.
* strncmp and _fstrncmp perform an unsigned
comparison of s1 to s2.
* strncmpi (implemented as a macro that calls
strnicmp) performs a signed comparison of
s1 to s2, without case sensitivity.
* strnicmp and _fstrnicmp perform a signed
comparison of s1 to s2, without case
sensitivity.
The string comparison starts with the first
character in each string and continues with
subsequent characters until the corresponding
characters differ or until maxlen characters
have been examined.
To use strncmpi, you must include STRING.H.
This macro is provided for compatibility with
other C compilers.
Return Value:
These routines return an int value based on
the result of comparing s1 (or part of it)
to s2 (or part of it):
* < 0 if s1 < s2
* == 0 if s1 == s2
* > 0 if s1 > s2
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strncmp | Yes | Yes | Yes | Yes | |
strncmpi | Yes | | Yes | | |
strnicmp | Yes | | Yes | | |
_fstrncmp | Yes | | Yes | | |
_fstrnicmp | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
_fstrcmp and _fstricmp
strcmp, strcmpi, and stricmp
Examples:
strncmp example
strncmpi example
strnicmp example
strncmp Example
=================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");
ptr = strncmp(buf2,buf3,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");
return(0);
}
strncmpi Example
==================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");
if (ptr == 0)
printf("buffer 2 equals buffer 1\n");
return 0;
}
strnicmp Example
==================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strnicmp(buf2, buf1, 3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1\n");
if (ptr == 0)
printf("buffer 2 equals buffer 1\n");
return 0;
}
=============
_fstrncpy,
strncpy <STRING.H>
=============
Copies at most maxlen characters of src to dest
Declaration:
* char *strncpy(char *dest, const char *src, size_t maxlen);
* char far * far _fstrncpy(char far *dest, const char far *src,
size_t maxlen);
Remarks:
strncpy copies up to maxlen characters from
src into dest, truncating or null-padding
dest. _fstrncpy is the far version.
The target string, dest, might not be
null-terminated if the length of src is
maxlen or more.
Return Value: dest
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strncpy | Yes | Yes | Yes | Yes | |
_fstrncpy | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
strcpy
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
strncpy(string, str1, 3);
string[3] = '\0';
printf("%s\n", string);
return 0;
}
=============
_fstrnset,
strnset <STRING.H>
=============
Sets the first n characters of s to ch
Declaration:
* char *strnset(char *s, int ch, size_t n);
* char far * far _fstrnset(char far *s, int ch, size_t n);
Remarks:
strnset copies the character ch into the
first n bytes of the string s . _fstrnset is
the far version.
If n > strlen(s), strlen(s) replaces n.
Copying stops when n characters have been
set, or when a null character is found.
Return Value:
strnset returns s.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
printf("string before strnset: %s\n", string);
strnset(string, letter, 13);
printf("string after strnset: %s\n", string);
return 0;
}
=============
_fstrpbrk,
strpbrk <STRING.H>
=============
Scans one string for the first occurrence of
any character that is in a second string
Declaration:
* char *strpbrk(const char *s1, const char *s2);
* char far *far _fstrpbrk(const char far *s1, const char far *s2);
Remarks:
strpbrk scans a string, s1, for the first
occurrence of any character appearing in s2.
_fstrpbrk is the far version.
Return Value:
* On success, strpbrk returns a pointer to
the first occurrence of any of the
characters in s2.
* If none of the s2 characters occur in s1,
it returns null.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strpbrk | Yes | Yes | Yes | Yes | |
_fstrpbrk | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr;
ptr = strpbrk(string1, string2);
if (ptr)
printf("strpbrk found first character: %c\n", *ptr);
else
printf("strpbrk didn't find character in set\n");
return 0;
}
=============
_fstrrchr,
strrchr <STRING.H>
=============
Finds the last occurrence of c in s
Declaration:
* char *strrchr(const char *s, int c);
* char far * far _fstrrchr(const char far *s, int c);
Remarks:
strrchr scans a string in the reverse
direction, looking for a specific character.
_fstrrchr is the far version.
strrchr finds the last occurrence of the
character c in the string s.
The null-terminator is considered to be part
of the string.
Return Value:
* On success, strrchr returns a pointer to
the last occurrence of the character c.
* If c does not occur in s, strrchr returns
null.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strrchr | Yes | Yes | Yes | Yes | |
_fstrrchr | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strrchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}
============
_fstrrev,
strrev <STRING.H>
============
Reverses all characters in s (except for the terminating null)
Declaration:
* char *strrev(char *s);
* char far * far _fstrrev(char far *s);
Remarks:
strrev and _fstrrev changes all characters in
a string to reverse order, except the
terminating null character.
For example, it would change
string\0
to
gnirts\0.)
Return Value:
strrev returns a pointer to the reversed
string.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *forward = "string";
printf("Before strrev(): %s\n", forward);
strrev(forward);
printf("After strrev(): %s\n", forward);
return 0;
}
============
_fstrset,
strset <STRING.H>
============
Sets all characters in s to ch
Declaration:
* char *strset(char *s, int ch);
* char far * far _fstrset(char far *s, int ch);
Remarks:
strset and _fstrset set all characters in the
string s to the character ch.
It quits when the terminating null character
is found.
Return Value:
Returns s.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10] = "123456789";
char symbol = 'c';
printf("Before strset(): %s\n", string);
strset(string, symbol);
printf("After strset(): %s\n", string);
return 0;
}
============
_fstrstr, <STRING.H>
strstr
============
Finds the first occurrence of a substring in another string
Declaration:
* char *strstr(const char *s1, const char *s2);
* char far * far _fstrstr(const char far *s1, const char far *s2);
Remarks:
strstr and _fstrstr scan s1 for the first
occurrence of the substring s2.
Return Value:
* On success, strstr returns a pointer to the element in s1 where s2
begins (points to s2 in s1).
* On error (if s2 does not occur in s1), strstr returns null.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strstr | Yes | Yes | Yes | Yes | |
_fstrstr | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s\n", ptr);
return 0;
}
============
_fstrtok,
strtok <STRING.H>
============
Scans s1 for the first token not contained in s2
Declaration:
* char *strtok(char *s1, const char *s2);
* char far * far _fstrtok(char far *s1, const char far *s2);
Remarks:
strtok and _fstrtok consider 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
until no tokens remain.
The separator string, s2, can be different
from call to call.
Return Value:
* On success, returns a pointer to the token found in s1.
* When there are no more tokens, returns a null pointer
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
strtok | Yes | Yes | Yes | Yes | |
_fstrtok | Yes | | Yes | | |
+-----+------+---------+--------+----------+
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char input[16] = "abc,d";
char *p;
/* strtok places a NULL terminator
in front of the token, if found */
p = strtok(input, ",");
if (p) printf("%s\n", p);
/* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
p = strtok(NULL, ",");
if (p) printf("%s\n", p);
return 0;
}
=========
strxfrm <STRING.H>
=========
Transforms a portion of a string
Declaration: size_t strxfrm(char *s1, char *s2, size_t n);
Remarks:
strxfrm transforms the string *s2 into the
string *s1 for no more than n characters.
Return Value:
The number of characters in the resulting
transformed string, not including the null
terminator.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | Yes | |
+-----+------+---------+--------+----------+
Example:
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *target;
char *source = "Frank Borland";
int length;
/* allocate space for the target string */
target = (char *) calloc(80, sizeof(char));
/* copy the source over to the target and get the length */
length = strxfrm(target, source, 80);
/* print out the results */
printf("%s has the length %d\n", target, length);
return 0;
}
==========
MEMORY.H
==========
Includes
========
MEM.H
==================
_fmem... and
mem... functions <MEM.H, STRING.H>
==================
* memccpy copies a block of n bytes from src to dest
* memcpy copies a block of n bytes from src to dest
* memmove copies a block of n bytes from src to dest
* memchr searches the first n bytes of array s for character c
* memcmp compares the first n bytes of strings s1 and s2
* memicmp compares the first n bytes of strings s1 and s2, ignoring case
* memset sets n bytes of s to byte c
Declaration (near versions):
* void *memccpy(void *dest, const void *src, int c, size_t n);
* void *memcpy (void *dest, const void *src, size_t n);
* void *memmove(void *dest, const void *src, size_t n);
* void *memchr (const void *s, int c, size_t n);
* int memcmp (const void *s1, const void *s2, size_t n);
* int memicmp(const void *s1, const void *s2, size_t n);
* void *memset (void *s, int c, size_t n);
Declaration (far versions):
* void far * far _fmemccpy(void far *dest, const void far *src, int c,
size_t n);
* void far * far _fmemcpy (void far *dest, const void far *src,
size_t n);
* void far * far _fmemchr(const void far *s, int c, size_t n);
* void far * far _fmemset(void far *s, int c, size_t n);
* int far _fmemcmp (const void far *s1, const void far *s2, size_t n);
* int far _fmemicmp(const void far *s1, const void far *s2, size_t n);
======================
_fmemccpy, _fmemcpy, <MEM.H, STRING.H>
memccpy, memcpy,
memmove
======================
Copies a block of n bytes from src to dest
Declaration:
* void *memccpy(void *dest, const void *src, int c, size_t n);
* void *memcpy (void *dest, const void *src, size_t n);
* void *memmove(void *dest, const void *src, size_t n);
* void far * far _fmemccpy(void far *dest, const void far *src,
int c, size_t n);
* void far * far _fmemcpy (void far *dest, const void far *src,
size_t n);
Remarks:
Each of these functions copies a block of n
bytes from src to dest.
* With memccpy, the copying stops as soon as
either of the following occurs:
* the character c is first copied into dest
* n bytes have been copied into dest
* With memcpy, if src and dest overlap, the
behavior is undefined.
* With memmove, even when the src and dest
blocks overlap, bytes in the overlapping
locations are copied correctly.
Return Value:
* If c was copied, memccpy returns a
pointer to the byte in dest immediately
following c.
* Otherwise, memccpy returns null.
* memcpy and memmove return dest.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
memccpy | Yes | Yes | Yes | | |
memcpy | Yes | Yes | Yes | Yes | |
memmove | Yes | Yes | Yes | Yes | |
_fmemccpy | Yes | | Yes | | |
_fmemcpy | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
memset
movmem
Summary of all mem... functions
Examples:
memccpy example
memcpy example
memmove example
memmove example
=================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
char *src = "******************************";
printf("destination prior to memmove: %s\n", dest);
memmove(dest, src, 26);
printf("destination after memmove: %s\n", dest);
return 0;
}
memccpy example
=================
#include <string.h>
#include <stdio.h>
int main(void)
{
char *src = "This is the source string";
char dest[50];
char *ptr;
ptr = (char *) memccpy(dest, src, 'c', strlen(src));
if (ptr)
{
*ptr = '\0';
printf("The character was found: %s\n", dest);
}
else
printf("The character wasn't found\n");
return 0;
}
memcpy example
================
#include <stdio.h>
#include <string.h>
int main(void)
{
char src[] = "******************************";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
char *ptr;
printf("destination before memcpy: %s\n", dest);
ptr = (char *) memcpy(dest, src, strlen(src));
if (ptr)
printf("destination after memcpy: %s\n", dest);
else
printf("memcpy failed\n");
return 0;
}
===========
_fmemchr,
memchr <MEM.H, STRING.H>
===========
Searches n bytes for character c
Declaration:
* void *memchr (const void *s, int c, size_t n);
* void far * far _fmemchr(const void far *s, int c, size_t n);
Remarks:
memchr searches the first n bytes of the
block *s for character c.
Return Value
* On success, returns a pointer to the
first occurrence of c in s.
* Otherwise, returns null.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
memchr | Yes | Yes | Yes | Yes | |
_fmemchr | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
Summary of all mem... functions
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char str[17];
char *ptr;
strcpy(str, "This is a string");
ptr = (char *) memchr(str, 'r', strlen(str));
if (ptr)
printf("The character 'r' is at position: %d\n", ptr - str);
else
printf("The character was not found\n");
return 0;
}
=======================
_fmemcmp, _fmemicmp, <MEM.H, STRING.H>
memcmp, memicmp
=======================
* memcmp compares the first n bytes of strings s1 and s2
* memicmp compares the first n bytes of strings s1 and s2, ignoring case
Declaration:
* int memcmp (const void *s1, const void *s2, size_t n);
* int memicmp(const void *s1, const void *s2, size_t n);
* int far _fmemcmp (const void far *s1, const void far *s2, size_t n);
* int far _fmemicmp(const void far *s1, const void far *s2, size_t n);
Remarks:
* memcmp compares the first n bytes of the
blocks s1 and s2 as unsigned chars.
* memicmp compares the first n bytes of the
blocks s1 and s2, ignoring character case
(upper or lower).
Return Value:
Because they compare bytes as unsigned chars,
memcmp and memicmp return a value
* < 0 if s1 < s2
* = 0 if s1 == s2
* > 0 if s1 > s2
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
memcmp | Yes | Yes | Yes | Yes | |
memicmp | Yes | Yes | Yes | | |
_fmemcmp | Yes | | Yes | | |
_fmemicmp | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
Summary of all mem... functions
Examples:
memcmp example
memicmp example
memcmp example
================
#include <stdio.h>
#include <string.h>
int main(void)
{
char *buf1 = "aaa";
char *buf2 = "bbb";
char *buf3 = "ccc";
int stat;
stat = memcmp(buf2, buf1, strlen(buf2));
if (stat > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");
stat = memcmp(buf2, buf3, strlen(buf2));
if (stat > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");
return 0;
}
memicmp example
=================
#include <stdio.h>
#include <string.h>
int main(void)
{
char *buf1 = "ABCDE123";
char *buf2 = "abcde456";
int stat;
stat = memicmp(buf1, buf2, 5);
printf("The strings to position 5 are ");
if (stat)
printf("not ");
printf("the same\n");
return 0;
}
===========
_fmemset,
memset <MEM.H, STRING.H>
===========
Sets n bytes of s to byte c
Declaration:
* void *memset (void *s, int c, size_t n);
* void far * far _fmemset(void far *s, int c, size_t n);
Remarks:
memset sets the first n bytes of the array s
to the character c.
Return Value:
Returns s.
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
memset | Yes | Yes | Yes | Yes | |
_fmemset | Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
Summary of all mem... functions
Example:
#include <string.h>
#include <stdio.h>
#include <mem.h>
int main(void)
{
char buffer[] = "Hello world\n";
printf("Buffer before memset: %s\n", buffer);
memset(buffer, '*', strlen(buffer) - 1);
printf("Buffer after memset: %s\n", buffer);
return 0;
}
==========
movedata <MEM.H, STRING.H>
==========
Copies n bytes
Declaration:
void movedata(unsigned srcseg, unsigned srcoff,
unsigned destseg, unsigned destoff, size_t n);
Remarks:
movedata copies n bytes from the source
address (srcseg:srcoff) to the destination
address (destseg:destoff).
movedata is a means of moving blocks of data
that is independent of memory model.
Return Value: None
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
FP_OFF
memcpy
MK_FP
movmem
segread
Example:
#include <mem.h>
#define MONO_BASE 0xB000
char buf[80*25*2];
/* saves the contents of the monochrome screen in buffer */
void save_mono_screen(char near *buffer)
{
movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2);
}
int main(void)
{
save_mono_screen(buf);
return 0;
}
========
movmem <MEM.H>
========
Moves a block of length bytes from src to dest
Declaration: void movmem(void *src, void *dest, unsigned length);
Remarks:
movmem moves a block of length bytes from src
to dest.
Even if the source and destination blocks
overlap, the move direction is chosen so that
the data is always moved correctly.
Return Value: None
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
memcpy
memmove
movedata
Example:
#include <mem.h>
#include <alloc.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char *source = "Borland International";
char *destination;
int length;
length = strlen(source);
destination = (char *) malloc(length + 1);
movmem(source, destination, length);
printf("%s\n", destination);
return 0;
}
========
setmem <mem.H>
========
Assigns a value to a range of memory
Declaration: void setmem(void *dest, unsigned length, char value);
Remarks:
setmem sets a block of length bytes, *dest,
to the byte "value".
Return Value: None
Portability:
+ DOS + UNIX + Windows + ANSI C + C++ Only +
| Yes | | Yes | | |
+-----+------+---------+--------+----------+
See Also:
memset
strset
Example:
#include <stdio.h>
#include <alloc.h>
#include <mem.h>
int main(void)
{
char *dest;
dest = (char *) calloc(21, sizeof(char));
setmem(dest, 20, 'c');
printf("%s\n", dest);
return 0;
}