INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 3: Working with Character and String Data Types
Home Contents Index Master Index New Book

Character and String Library Functions

The ESQL/C library contains the following character-manipulation functions. You can use these functions in your C programs to manipulate single characters and strings of bytes and characters, including variable-length expressions of the following data types:

The internal structure referenced by the lvarchar pointer data type is different than the character representation of a fixed-size lvarchar variable. You must use the ifx_var() functions to manipulate lvarchar pointer variables. For more information on the ifx_var() functions, see "The lvarchar pointer and var binary Library Functions".

The functions whose names begin with by act on and return fixed-length strings of bytes. The functions whose names begin with rst and st (except stchar) operate on and return null-terminated strings. The rdownshift() and rupshift() functions also operate on null-terminated strings but do not return values.

(1 of 2)

Function Name Description

bycmpr()

Compares two groups of contiguous bytes

bycopy()

Copies bytes from one area to another

byfill()

Fills an area you specify with a character

byleng()

Counts the number of bytes in a string

ldchar()

Copies a fixed-length string to a null-terminated string

rdownshift()

Converts all letters to lowercase

rstod()

Converts a string to a double value

rstoi()

Converts a string to a short integer value

rstol()

Converts a string to a long integer value

rupshift()

Converts all letters to uppercase

stcat()

Concatenates one string to another

stchar()

Copies a null-terminated string to a fixed-length string

stcmpr()

Compares two strings

stcopy()

Copies one string to another string

stleng()

Counts the number of bytes in a string

When you compile your ESQL/C program with the esql preprocessor, it calls on the linker to link these functions to your program. The following pages describe each of these functions.

bycmpr()

The bycmpr() function compares two groups of contiguous bytes for a given length. It returns the result of the comparison as its value.

Syntax

Usage

The bycmpr() function performs a byte-by-byte comparison of the two groups of contiguous bytes until it finds a difference or until it compares length number of bytes. The bycmpr() function returns an integer whose value (0, -1, or +1) indicates the result of the comparison between the two groups of bytes.

The bycmpr() function subtracts the bytes of the byte2 group from those of the byte1 group to accomplish the comparison.

Return Codes

0

The two groups are identical.

-1

The byte1 group is less than the byte2 group.

+1

The byte1 group is greater than the byte2 group.

Example

This sample program is in the bycmpr.ec file in the demo directory.

Example Output

bycopy()

The bycopy() function copies a given number of bytes from one location to another.

Syntax

Important: Take care not to overwrite areas of memory adjacent to the destination area.

Example

This sample program is in the bycopy.ec file in the demo directory.

Example Output

byfill()

The byfill() function fills a specified area with one character.

Syntax

Important: Take care not to overwrite areas of memory adjacent to the area that you want byfill() to fill.

Example

This sample program is in the byfill.ec file in the demo directory.

Example Output

byleng()

The byleng() function returns the number of significant characters in a string, not counting trailing blanks.

Syntax

Example

This sample program is in the byleng.ec file in the demo directory.

Example Output

ldchar()

The ldchar() function copies a fixed-length string into a null-terminated string and removes any trailing blanks.

Syntax

Example

This sample program is in the ldchar.ec file in the demo directory.

Example Output

rdownshift()

The rdownshift() function changes all the uppercase characters within a null-terminated string to lowercase characters.

Syntax

Usage

The rdownshift() function refers to the current locale to determine uppercase and lowercase letters. For the default locale, U.S. English, rdownshift() uses the ASCII lowercase (a-z) and uppercase (A-Z) letters.

GLS
If you use a nondefault locale, rdownshift() uses the lowercase and uppercase letters that the locale defines. For more information, see the
Informix Guide to GLS Functionality.

Example

This sample program is in the rdownshift.ec file in the demo directory.

Example Output

rstod()

The rstod() function converts a null-terminated string into a double value.

Syntax

Return Codes

=0

The conversion was successful.

!=0

The conversion failed.

Example

This sample program is in the rstod.ec file in the demo directory.

Example Output

rstoi()

The rstoi() function converts a null-terminated string into a short integer value.

Syntax

Usage

The legal range of values is from -32767 to 32767. The value -32768 is not valid because this value is a reserved value that indicates null.

If string corresponds to a null integer, ival points to the representation for a SMALLINT null. To convert a string that corresponds to a long integer, use rstol(). Failure to do so can result in corrupt data representation.

Return Codes

=0

The conversion was successful.

!=0

The conversion failed.

Example

This sample program is in the rstoi.ec file in the demo directory.

Example Output

rstol()

The rstol() function converts a null-terminated string into a long integer value.

Syntax

Usage

The legal range of values is from -2,147,483,647 to 2,147,483,647. The value -2,147,483,648 is not valid because this value is a reserved value that indicates null.

Return Codes

=0

The conversion was successful.

!=0

The conversion failed.

Example

This sample program is in the rstol.ec file in the demo directory.

Example Output

rupshift()

The rupshift() function changes all the characters within a null-terminated string to uppercase characters.

Syntax

Usage

The rupshift() function refers to the current locale to determine uppercase and lowercase letters. For the default locale, U.S. English, rupshift() uses the ASCII lowercase (a-z) and uppercase (A-Z) letters.

GLS
If you use a nondefault locale, rupshift() uses the lowercase and uppercase letters that the locale defines. For more information, see the
Informix Guide to GLS Functionality.

Example

This sample program is in the rupshift.ec file in the demo directory.

Example Output

stcat()

The stcat() function concatenates one null-terminated string to the end of another.

Syntax

Example

This sample program is in the stcat.ec file in the demo directory.

Example Output

stchar()

The stchar() function stores a null-terminated string in a fixed-length string, padding the end with blanks, if necessary.

Syntax

Example

This sample program is in the stchar.ec file in the demo directory.

Example Output

stcmpr()

The stcmpr() function compares two null-terminated strings.

Syntax

Important: s1 is greater than s2 when s1 appears after s2 in the ASCII collation sequence.

Return Codes

=0

The two strings are identical.

<0

The first string is less than the second string.

>0

The first string is greater than the second string.

Example

This sample program is in the stcmpr.ec file in the demo directory.

Example Output

stcopy()

The stcopy() function copies a null-terminated string from one location in memory to another location.

Syntax

Example

This sample program is in the stcopy.ec file in the demo directory.

Example Output

stleng()

The stleng() function returns the length, in bytes, of a null-terminated string that you specify.

Syntax

Usage

The length does not include the null terminator.

Example

This sample program is in the stleng.ec file in the demo directory.

Example Output


 




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.