The ifx_int8cvasc() function
The ifx_int8cvasc() function converts a value held as printable characters in a C char type into an int8 type number.
Syntax
mint ifx_int8cvasc(strng_val, len, int8_val)
char *strng_val
mint len;
ifx_int8_t *int8_val;
- strng_val
- A pointer to a string.
- len
- The length of the strng_val string.
- int8_val
- A pointer to the int8 structure where ifx_int8cvasc() places the result of the conversion.
Usage
The character string, strng_val,
can contain the following symbols:
- A leading sign, either a plus (+) or minus (-).
- An exponent that is preceded by either
e
orE
. You can precede the exponent by a sign, either a plus (+) or minus (-).
The strng_val character string does not contain a decimal separator or digits to the right of the decimal separator. The ifx_int8cvasc() function truncates the decimal separator and any digits to the right of the decimal separator. The ifx_int8cvasc() function ignores leading spaces in the character string.
When you use a nondefault locale (one other than US English), ifx_int8cvasc() supports non-ASCII characters in the strng_val character string. For more information, see the Informix® GLS User's Guide.
Return codes
- 0
- The conversion was successful.
- -1213
- The string has non-numeric characters.
- -1284
- The operation resulted in overflow or underflow.
Example
The file int8cvasc.ec in
the demo directory contains the following sample
program.
/*
* ifx_in8cvasc.ec *
The following program converts three strings to INT8
types and displays the values stored in each field of
the INT8 structures.
*/
#include <stdio.h>
EXEC SQL include "int8.h";
char string1[] = "-12,555,444,333,786,456";
char string2[] = "480";
char string3[] = "5.2";
main()
{
mint x;
ifx_int8_t num1, num2, num3;
void nullterm(char *, mint);
printf("IFX_INT8CVASC Sample ESQL Program running.\n\n");
if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{
printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}
/* Display the exponent, sign value and number of digits in num1. */
ifx_int8toasc(&num1, string1, sizeof(string1));
nullterm(string1, sizeof(string1));
printf("The value of the first INT8 is = %s\n", string1);
/* Display the exponent, sign value and number of digits in num2. */
ifx_int8toasc(&num2, string2, sizeof(string2));
nullterm(string2, sizeof(string2));
printf("The value of the 2nd INT8 is = %s\n", string2);
/* Display the exponent, sign value and number of digits in num3. */
/* Note that the decimal is truncated */
ifx_int8toasc(&num3, string3, sizeof(string3));
nullterm(string3, sizeof(string3));
printf("The value of the 3rd INT8 is = %s\n", string3);
printf("\nIFX_INT8CVASC Sample Program over.\n\n");
exit(0);
}
void nullterm(char *str, mint size)
{
char *end;
end = str + size;
while(*str && *str > ' ' && str <= end)
++str;
*str = '\0';
}
Output
IFX_INT8CVASC Sample ESQL Program running.
The value of the first INT8 is = -12555444333786456
The value of the 2nd INT8 is = 480
The value of the 3rd INT8 is = 5
IFX_INT8CVASC Sample Program over.