The ifx_int8toasc() function

The ifx_int8toasc() function converts an int8 type number to a C char type value.

Syntax

mint ifx_int8toasc(int8_val, strng_val, len)
   ifx_int8_t *int8_val;
   char  *strng_val;
   mint  len;
int8_val
A pointer to the int8 structure whose value ifx_int8toasc() converts to a text string.
strng_val
A pointer to the first byte of the character buffer where the ifx_int8toasc() function places the text string.
len
The size of strng_val, in bytes, minus 1 for the null terminator.

Usage

If the int8 number does not fit into a character string of length len, ifx_int8toasc() converts the number to an exponential notation. If the number still does not fit, ifx_int8toasc() fills the string with asterisks. If the number is shorter than the string, ifx_int8toasc() left-justifies the number and pads it on the right with blanks.

Because the character string that ifx_int8toasc() returns is not null terminated, your program must add a null character to the string before you print it.

When you use a nondefault locale (one other than US English), ifx_int8toasc() 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.
-1207
The converted value does not fit into the allocated space.

Example

The file int8toasc.ec in the demo directory contains the following sample program.
/*
   * ifx_int8toasc.ec *

    The following program converts three string
    constants to INT8 types and then uses ifx_int8toasc()
    to convert the INT8 values to C char type values.
*/

#include <stdio.h>
#define END sizeof(result)

EXEC SQL include "int8.h";

char string1[] = "-12,555,444,333,786,456";
char string2[] = "480";
char string3[] = "5.2";
char result[40];

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

    printf("IFX_INT8TOASC 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 back to ASCII\n");
    printf(" Executing: ifx_int8toasc(&num1, result, END - 1)");
    if (x = ifx_int8toasc(&num1, result, END - 1))
        printf("\tError %d in converting INT8 to string\n", x);
    else
        {
        result[END - 1] = '\0';             /* null terminate */
        printf("\n The value of the first INT8 is = %s\n", result);
        }
    printf("\nConverting second INT8 back to ASCII\n");
    printf(" Executing: ifx_int8toasc(&num2, result, END - 1)");
    if (x= ifx_int8toasc(&num2, result, END - 1))
        printf("\tError %d in converting INT8 to string\n", x);
    else
        {
        result[END - 1] = '\0';             /* null terminate */
        printf("\n The value of the 2nd INT8 is = %s\n", result);
        }

    printf("\nConverting third INT8 back to ASCII\n");
    printf(" Executing: ifx_int8toasc(&num3, result, END - 1)"); 
    /* note that the decimal is truncated */

    if (x= ifx_int8toasc(&num3, result, END - 1))
        printf("\tError %d in converting INT8 to string\n", x);
    else
        {
        result[END - 1] = '\0';                 /* null terminate */
        printf("\n The value of the 3rd INT8 is = %s\n", result);
        }
    printf("\nIFX_INT8TOASC Sample Program over.\n\n");
    exit(0);
}

Output

IFX_INT8TOASC Sample ESQL Program running.


Converting INT8 back to ASCII
 Executing: ifx_int8toasc(&num1, result, sizeof(result)-1)
 The value of the first INT8 is = -12555444333786456

Converting second INT8 back to ASCII
 Executing: ifx_int8toasc(&num2, result, sizeof(result)-1)
 The value of the 2nd INT8 is = 480

Converting third INT8 back to ASCII
 Executing: ifx_int8toasc(&num3, result, END)
 The value of the 3rd INT8 is = 5

IFX_INT8TOASC Sample Program over.