The ifx_int8toint() function

The ifx_int8toint() function converts an int8 type number into a C int type number.

Syntax

mint ifx_int8toint(int8_val, int_val)
   ifx_int8_t *int8_val;
   mint *int_val;
int8_val
A pointer to an int8 structure whose value ifx_int8toint() converts to an mint type value.
int_val
A pointer to an mint value where ifx_int8toint() places the result of the conversion.

Usage

The ifx_int8toint() library function converts an int8 value to a C integer. The size of a C integer depends upon the hardware and operating system of the computer you are using. Therefore, the ifx_int8toint() function equates an integer value with the SQL SMALLINT data type. The valid range of a SMALLINT is between 32767 and -32767. To convert larger int8 values to larger integers, use the ifx_int8tolong() library function.

Return codes

0
The conversion was successful.
<0
The conversion failed.

Example

The file int8toint.ec in the demo directory contains the following sample program.
/*
   * ifx_int8toint.ec *

   The following program converts three strings to INT8 types and
   converts the INT8 type values to C integer type values.
   Then the values are displayed.

*/

#include <stdio.h>

EXEC SQL include "int8.h";

char string1[] = "-12,555";
char string2[] = "480";
char string3[] = "5.2";

main()
{
    mint x;
    mint i =0;
    ifx_int8_t num1, num2, num3;

    printf("IFX_INT8TOINT 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);
        }
    printf("\nConverting INT8 to integer\n");
    if (x= ifx_int8toint(&num1, &i))
        {
        printf("\tError %d in converting INT8 to integer\n", x);
        exit(1);
        }
    else 
        {
        printf("String 1= %s\n", string1);
        printf("INT8 value is = %d\n", i);
        }
printf("\nConverting second INT8 to integer\n");
    if (x= ifx_int8toint(&num2, &i))
        {
        printf("\tError %d in converting INT8 to integer\n", x);
        exit(1);
        }
    else 
        {
        printf("String2 = %s\n", string2);
        printf("INT8 value is =  %d\n", i);
        }
   printf("\nConverting third INT8 to integer\n");
 
    /* note that the decimal will be truncated */
 
    if (x= ifx_int8toint(&num3, &i))
        {
        printf("\tError %d in converting INT8 to integer\n", x);
        exit(1);
        }
    else
        {
        printf("String3 = %s\n", string3);
        printf("INT8 value is =  %d\n",i);
        }
    printf("\nIFX_INT8TOINT Sample Program over.\n\n");
    exit(0);
}

Output

IFX_INT8TOINT Sample ESQL Program running.



Converting INT8 to integer
 
Executing: ifx_int8toint(&num1,&i)
String 1= -12,555
The value of the first integer is = -12555


Converting second INT8 to integer
 
Executing: ifx_int8toint(&num2, &i)
String2 = 480
The value of the second integer is =  480


Converting third INT8 to integer
 
Executing: ifx_int8toint(&num3, &i)
String3 = 5.2
The value of the third integer is =  5

IFX_INT8TOINT Sample Program over.