 |
INFORMIX-ESQL/C Programmer's Manual ESQL/C Function Library |
|
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
Example
This sample program is in the rstoi.ec file in the demo directory.
/*
* rstoi.ec *
The following program tries to convert three strings to integers.
It displays the result of each conversion.
*/
#include <stdio.h>
EXEC SQL include sqltypes;
main()
{
mint err;
mint i;
short s;
printf("RSTOI Sample ESQL Program running.\n\n");
i = 0;
printf("Converting String 'abc':\n");
if((err = rstoi("abc", &i)) == 0)
printf("\tResult = %d\n\n", i);
else
printf("\tError %d in conversion of string #1\n\n", err);
i = 0;
printf("Converting String '32766':\n");
if((err = rstoi("32766", &i)) == 0)
printf("\tResult = %d\n\n", i);
else
printf("\tError %d in conversion of string #2\n\n", err);
i = 0;
printf("Converting String '':\n");
if((err = rstoi("", &i)) == 0)
{
s = i; /* assign to a SHORT variable */
if (risnull(CSHORTTYPE, (char *) &s)) /* and then test for NULL */
printf("\tResult = NULL\n\n");
else
printf("\tResult = %d\n\n", i);
}
else
printf("\tError %d in conversion of string #3\n\n", err);
printf("\nRSTOI Sample Program over.\n\n");
}
Output
INFORMIX-ESQL/C Programmer's Manual, Version 9.21
Copyright © 1999, Informix Software, Inc. All rights reserved