The ifx_int8tolong() function
The ifx_int8tolong() function converts an int8 type number into a C long type number.
Syntax
mint ifx_int8tolong(int8_val, lng_val)
ifx_int8_t *int8_val;
int4 *lng_val;
- int8_val
- A pointer to an int8 structure whose value ifx_int8tolong() converts to an int4 integer type value.
- lng_val
- A pointer to an int4 integer where ifx_int8tolong() places the result of the conversion.
Return codes
- 0
- The conversion was successful.
- -1200
- The magnitude of the int8 type number is greater than 2,147,483,647.
Example
The file int8tolong.ec in
the demo directory contains the following sample
program.
/*
* ifx_int8tolong.ec *
The following program converts three strings to INT8 types and
converts the INT8 type values to C long type values.
Then the values are displayed.
*/
#include <stdio.h>
EXEC SQL include "int8.h";
char string1[] = "-1,555,345,698";
char string2[] = "3,235,635";
char string3[] = "553.24";
main()
{
int x;
long l =0;
ifx_int8_t num1, num2, num3;
printf("IFX_INT8TOLONG 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 long\n");
if (x= ifx_int8tolong(&num1, &l))
{
printf("\tError %d in converting INT8 to long\n", x);
exit(1);
}
else
{
printf("String 1= %s\n", string1);
printf("INT8 value is = %d\n", l);
}
printf("\nConverting second INT8 to long\n");
if (x= ifx_int8tolong(&num2, &l))
{
printf("\tError %d in converting INT8 to long\n", x);
exit(1);
}
else
{
printf("String2 = %s\n", string2);
printf("INT8 value is = %d\n",l);
}
printf("\nConverting third INT8 to long\n");
/* Note that the decimal places will be truncated. */
if (x= ifx_int8tolong(&num3, &l))
{
printf("\tError %d in converting INT8 to long\n", x);
exit(1);
}
else
{
printf("String3 = %s\n", string3);
printf("INT8 value is = %d\n",l);
}
printf("\nIFX_INT8TOLONG Sample Program over.\n\n");
exit(0);
}
Output
IFX_INT8TOLONG Sample ESQL Program running.
Converting INT8 to long
Executing: ifx_int8tolong(&num1,&l)
String 1= -1,555,345,698
The value of the first long is = -1555345698
Converting second INT8 to long
Executing: ifx_int8tolong(&num2, &l)
String2 = 3,235,635
The value of the second long is = 3235635
Converting third INT8 to long
Executing: ifx_int8tolong(&num3, &l)
String3 = 553.24
The value of the third long is = 553
IFX_INT8TOLONG Sample Program over.