AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
strton (String str, Pointer sptr [, int radix [, int fail]) yoix.string
 
Returns the number obtained by converting str to an integer, which is exactly the same answer that atoi would return. By default strton skips leading white space and then accepts an optional sign followed by a string of decimal digits. A character that is not a decimal digit stops the conversion and strton returns the integer value of the string up to that point. The String Pointer, sptr, when not NULL, is set to point to the first unrecognized character in str.

The optional radix argument, which is 10 by default, identifies the base of the number system used to convert str into its integer representation. A radix that is 0 means the initial characters in str, after the optional sign, determine the base which is hexadecimal if the first two characters are 0x or 0X, octal if the first character is 0, and decimal otherwise.

The optional fail argument, which is 0 by default, is the value that strton returns when no valid digits are found in str.
 
 Example:   The following example:
import yoix.*.*;

String a = "1st";
String b;

fprintf(stdout,
    "Example 1: a='%s'\n\
    strton(a, &b)='%d', b@sizeof='%d', b='%s'\n",
    a, strton(a, &b), b@sizeof, b);

a = "     +123  OK";
fprintf(stdout,
    "Example 2: a='%s'\n\
    strton(a, &b)='%d', b@sizeof='%d', b='%s'\n",
    a, strton(a, &b), b@sizeof, b);

a = "456";
fprintf(stdout,
    "Example 3: a='%s'\n\
    strton(a, &b)='%d', b@sizeof='%d', b=(rangecheck)'\n",
    a, strton(a, &b), b@sizeof);
prints these statements on standard output:
Example 1: a='1st'
    strton(a, &b)='1', b@sizeof='2', b='st'
Example 2: a='     +123  OK'
    strton(a, &b)='123', b@sizeof='4', b='  OK'
Example 3: a='456'
    strton(a, &b)='456', b@sizeof='0', b=(rangecheck)'
 
 Return:   int
 
 See Also:   atof, atoi, strtod

 

Yoix is a registered trademark of AT&T Inc.