lx4num_c |
Table of contents
Procedurelx4num_c (Scan for number) void lx4num_c ( ConstSpiceChar * string, SpiceInt first, SpiceInt * last, SpiceInt * nchar ) AbstractScan a string from a specified starting position for the end of a number. Required_ReadingNone. KeywordsPARSING Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- string I Any character string. first I First character to scan from in string. last O Last character that is part of a number. nchar O Number of characters in the number. Detailed_Inputstring is any character string. first is the location in the string to beginning scanning for a number. It is assumed that the number begins at first. The normal range of first is 0 : strlen(string)-1. Detailed_Outputlast is the last character at or after first such that the substring ranging from string[first] through string[last] is a number. If there is no such substring, last will be returned with the value first-1. If a number is found, last will be in the range is 0 : strlen(string)-1. nchar is the number of characters in the number that begins at index first and ends at last. If there is no such string nchar will be given the value 0. ParametersNone. Exceptions1) If `first' is beyond either end of the string, then `last' will be returned with the value first-1 and `nchar' will be returned with the value 0. 2) If string[first] is not part of a number then `last' will be returned with the value first-1 and `nchar' will be returned with the value 0. 3) If the `string' input string pointer is null, the error SPICE(NULLPOINTER) is signaled. 4) If the input string has length zero, `last' will be set to first-1 and `nchar' will be set to zero. This case is not considered an error. FilesNone. ParticularsThis routine allows you to scan forward in a string to locate a number that begins on the input character first. Note that all decimal numbers are included in the list of numbers. The main difference between decimal numbers and numbers is that numbers may have an exponential expression attached (i.e. the exponent character 'e','E','d' or 'D' followed by an signed integer). Examples1) Suppose you believe that a string has the form X%Y%Z where X, Y, and Z are numbers of some unknown length and % stands for any character that cannot occur in a number. You could use this routine to locate the numbers in the string as shown below. We'll keep track of the beginning and ending of the numbers in the integer arrays b and e. #include <string.h> #include "SpiceUsr.h" . . . first = 0; i = 0; len = strlen(string); while ( first < len-1 ) { lx4num_c ( string, first, &last, &nchar ); if ( nchar > 0 ) { i++; b[i] = first; e[i] = last; first = last + 2; } else { first++; } } RestrictionsNone. Literature_ReferencesNone. Author_and_InstitutionN.J. Bachman (JPL) J. Diaz del Rio (ODC Space) W.L. Taber (JPL) Version-CSPICE Version 1.0.1, 04-AUG-2021 (JDR) Edited the header to comply with NAIF standard. -CSPICE Version 1.0.0, 18-AUG-2002 (NJB) (WLT) Index_EntriesScan a string for a number. |
Fri Dec 31 18:41:09 2021