The rstol() function

The rstol() function converts a null-terminated string into a long integer value.

Syntax

mint rstol(string, long_int)
   char *string;
   mlong *long_int;
string
A pointer to a null-terminated string.
long_int
A pointer to an mlong value that holds the converted value.

Usage

The legal range of values is -2,147,483,647 - 2,147,483,647. The value -2,147,483,648 is not valid because this value is a reserved value that indicates null.

Return codes

=0
The conversion was successful.
!=0
The conversion failed.

Example

This sample program is in the rstol.ec file in the demo directory.
/*
   * rstol.ec *

   The following program tries to convert three strings to longs.  It
   displays the result of each attempt.
*/

#include <stdio.h>

EXEC SQL include sqltypes;

main()
{
    mint err;
    mlong l;

    printf("RSTOL Sample ESQL Program running.\n\n");

    l = 0;
    printf("Converting String 'abc':\n");
    if((err = rstol("abc", &l)) == 0)
      printf("\tResult = %ld\n\n", l);
    else
      printf("\tError %d in conversion of string #1\n\n", err);

    l = 0;
    printf("Converting String '2147483646':\n");
    if((err = rstol("2147483646", &l)) == 0)
      printf("\tResult = %ld\n\n", l);
    else
      printf("\tError %d in conversion of string #2\n\n", err);

    l = 0;
    printf("Converting String '':\n");
    if((err = rstol("", &l)) == 0)
      {
      if(risnull(CLONGTYPE, (char *) &l))
         printf("\tResult = NULL\n\n", l);
      else
         printf("\tResult = %ld\n\n", l);
      }
    else
      printf("\tError %d in conversion of string #3\n\n", err);

    printf("\nRSTOL Sample Program over.\n\n");
}

Output

RSTOL Sample ESQL Program running.

Converting String 'abc':
   Error -1213 in conversion of string #1

Converting String '2147483646':
   Result = 2147483646

Converting String '':
   Result = NULL


RSTOL Sample Program over.