Watcom C Library : strcmp, _fstrcmp, strcmpi, strcoll, strcpy, _fstrcpy, strcspn, _fstrcspn, strdup, _fstrdup
Watcom C Reference/S 2021. 11. 13. 20:38
Watcom C Library Reference : strcmp, _fstrcmp, strcmpi, strcoll, strcpy, _fstrcpy, strcspn, _fstrcspn, strdup, _fstrdup
strcmp, _fstrcmp
Synopsis : #include <string.h>
int strcmp( const char *s1, const char *s2 );
int _fstrcmp( const char __far *s1, const char __far *s2);
Description : The strcmp and _fstrcmp functions compare the string pointed to by s1 to the string pointed to by s2.
The _fstrcmp function is a data model independent form of the strcmp function that accepts far pointer arguments. It is most useful in mixed memory model applications.
Returns : The strcmp and _fstrcmp functions return an integer less than, equal to, or greater than zero, indicating that the string pointed to by s1 is less than, equal to, or greater than the string pointed to by s2.
See Also : stricmp, strncmp, strnicmp
Example :
#include <stdio.h>
#include <string.h>
void main( )
{
printf( "%d\n", strcmp( "abcdef", "abcdef" ) );
printf( "%d\n", strcmp( "abcdef", "abc" ) );
printf( "%d\n", strcmp( "abc", "abcdef" ) );
printf( "%d\n", strcmp( "abcdef", "mnopqr" ) );
printf( "%d\n", strcmp( "mnopqr", "abcdef" ) );
}
produces the following :
0
1
-1
-1
1
Classification : strcmp is ANSI, _fstrcmp is not ANSI
Systems : strcmp - All
_fstrcmp - All
strcmpi
Synopsis : #include <string.h>
int strcmpi( const char *s1, const char *s2 );
Description : The strcmpi function compares, with case insensitivity, the string pointed to by s1 to the string pointed to by s2. All uppercase characters from s1 and s2 are mapped to lowercase for the purposes of doing the comparison. The strcmpi function is identical to the stricmp function.
Returns : The strcmpi function returns an integer less than, equal to, or greater than zero, indicating that the string pointed to by s1 is less than, equal to, or greater than the string pointed to by s2.
See Also : strcmp, stricmp, strncmp, strnicmp
Example :
#include <stdio.h>
#include <string.h>
void main( )
{
printf( "%d\n", strcmpi( "AbCDEF", "abcdef" ) );
printf( "%d\n", strcmpi( "abcdef", "ABC" ) );
printf( "%d\n", strcmpi( "abc", "ABCdef" ) );
printf( "%d\n", strcmpi( "Abcdef", "mnopqr" ) );
printf( "%d\n", strcmpi( "Mnopar", "abcdef" ) );
}
produces the following :
0
100
-100
-12
12
Classification : WATCOM
Systems : All
strcoll
Synopsis : #include <string.h>
int strcoll( const char *s1, const char *s2 );
Description : The strcoll function compares the string pointed to by s1 to the string pointed to by s2. The comparison uses the collating sequence selected by the setlocale function. The function will be equivalent to the strcmp function when the collating sequence is selected from the "C" locale.
Returns : The strcoll function returns an integer less than, equal to, or greater than zero, indicating that the string pointed to by s1 is less than, equal to, or greater than the string pointed to by s2, according to the collating sequence selected.
See Also : setlocale, strncmp
Example :
#include <stdio.h>
#include <string.h>
char buffer[80] = "world";
void main( )
{
if( strcoll( buffer, "Hello" ) < 0 ) {
printf( "Less than\n" );
}
}
Classification : ANSI
Systems : All
strcpy, _fstrcpy
Synopsis : #include <string.h>
char *strcpy( char *dst, const char *src );
char __far *_fstrcpy( char __far *dst, const char __far *src);
Description : The strcpy and _fstrcpy functions copy the string pointed to by src (including the terminating null character) into the array pointed to by dst. Copying of overlapping objects is not guaranteed to work properly. See the description for the memmove function to copy objects that overlap.
The _fstrcpy function is a data model independent form of the strcpy function. It accepts far pointer arguments and returns a far pointer. It is most useful in mixed memory model applications.
Returns : The value of dst is returned.
See Also : strdup, strncpy
Example :
#include <stdio.h>
#include <string.h>
void main( )
{
auto char buffer[80];
strcpy( buffer, "Hello " );
strcat( buffer, "world" );
printf( "%s\n", buffer );
}
produces the following :
Hello world
Classification : strcpy is ANSI, _fstrcpy is not ANSI
Systems : strcpy - All
_fstrcpy - All
strcspn, _fstrcspn
Synopsis : #include <string.h>
size_t strcspn( const char *str, const char *charset );
size_t _fstrcspn( const char __far *str, const char __far *charset );
Description : The strcspn and _fstrcspn functions compute the length of the initial segment of the string pointed to by str which consists entirely of characters not from the string pointed to by charset. The terminating null character is not considered part of str.
The _fstrcspn function is a data model independent form of the strcspn function that accepts far pointer arguments. It is most useful in mixed memory model applications.
Returns : The length of the initial segment is returned.
See Also : strspn
Example :
#include <stdio.h>
#include <string.h>
void main( )
{
printf( "%d\n", strcspn( "abcbcadef", "cba" ) );
printf( "%d\n", strcspn( "xxxbcadef", "cba" ) );
printf( "%d\n", strcspn( "123456789", "cba" ) );
}
produces the following :
0
3
9
Classification : strcspn is ANSI, _fstrcspn is not ANSI
Systems : strcspn - All
_fstrcspn - All
strdup, _fstrdup
Synopsis : #include <string.h>
char *strdup( const char *src );
char __far *_fstrdup( const char __far *src );
Description : The strdup and _fstrdup functions create a duplicate copy of the string pointed to by src and returns a pointer to the new copy. For strdup, the memory for the new string is obtained by using the malloc function and can be freed using the free function. For _fstraup, the memory for the new string is obtained by using the _fmalloc function and can be freed using the _ffree function.
The _fstrdup function is a data model independent form of the strdup function that accepts far pointer arguments. It is most useful in mixed memory model applications.
Returns : The strdup and _fstrdup functions return the pointer to the new copy of the string if successful, otherwise it returns NULL.
See Also : free, malloc, strcpy, strncpy
Example :
#include <stdio.h>
#include <string.h>
void main( )
{
char *dup;
dup = strdup( "Make a copy" );
printf( "%s\n", dup );
}
Classification : WATCOM
Systems : strdup - All
_fstrdup- All
This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).
WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)