The rstod() function
The rstod() function converts a null-terminated string into a double value.
Syntax
mint rstod(string, double_val)
char *string;
double *double_val;
- string
- A pointer to a null-terminated string.
- double_val
- A pointer to a double value that holds the converted value.
Usage
- =0
- The conversion was successful.
- !=0
- The conversion failed.
Example
This sample program is in the rstod.ec file
in the demo directory.
/*
* rstod.ec *
The following program tries to convert three strings to doubles.
It displays the result of each attempt.
*/
#include <stdio.h>
main()
{
mint errnum;
char *string1 = "1234567887654321";
char *string2 = "12345678.87654321";
char *string3 = "zzzzzzzzzzzzzzzz";
double d;
printf("RSTOD Sample ESQL Program running.\n\n");
printf("Converting String 1: %s\n", string1);
if ((errnum = rstod(string1, &d)) == 0)
printf("\tResult = %f\n\n", d);
else
printf("\tError %d in conversion of string 1\n\n", errnum);
printf("Converting String 2: %s\n", string2);
if ((errnum = rstod(string2, &d)) == 0)
printf("\tResult = %.8f\n\n", d);
else
printf("\tError %d in conversion of string 2\n\n", errnum);
printf("Converting String 3: %s\n", string3);
if ((errnum = rstod(string3, &d)) == 0)
printf("\tResult = %.8f\n\n", d);
else
printf("\tError %d in conversion of string 3\n\n", errnum);
printf("\nRSTOD Sample Program over.\n\n");
}
Output
RSTOD Sample ESQL Program running.
Converting String 1: 123456788764321
Result = 1234567887654321.000000
Converting String 2: 12345678.87654321
Result = 12345678.87654321
Converting String 3: zzzzzzzzzzzzzzzz
Error -1213 in conversion of string 3
RSTOD Sample Program over.