Difference between revisions of "Dbatofld()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
(2 intermediate revisions by one user not shown) | |||
Line 11: | Line 11: | ||
<input parameters> | <input parameters> | ||
− | char *ascii; /* ASCII character string to be converted*/ | + | char *ascii; /* ASCII character string to be converted */ |
− | int width; /* Width of the field*/ | + | int width; /* Width of the field */ |
− | int decimal; /* Number of decimal places in the field*/ | + | int decimal; /* Number of decimal places in the field */ |
<output parameters> | <output parameters> | ||
− | char *field; | + | char *field; /* Address of the buffer where the converted string is returned */ |
− | + | ||
</code> | </code> | ||
Line 39: | Line 38: | ||
#include "dbl.h" | #include "dbl.h" | ||
− | char field[13]; /* Record field location */ | + | char field[13]; /* Record field location */ |
− | int rc; /* Return code | + | int rc; /* Return code */ |
rc = dbatofld("3245.876", 12, 3, field); | rc = dbatofld("3245.876", 12, 3, field); | ||
− | if (rc = =SUCCESS) printf("conversion | + | if (rc == SUCCESS) printf("conversion successful\n"); |
else { | else { | ||
− | printf("error number % | + | printf("error number %d\n",rc); |
exit(1); | exit(1); | ||
} | } |
Latest revision as of 11:20, 1 May 2009
PURPOSE
ASCII to numeric field
SYNOPSIS
#include "dbl.h" int dbatofld(ascii, width, decimal, field) <input parameters> char *ascii; /* ASCII character string to be converted */ int width; /* Width of the field */ int decimal; /* Number of decimal places in the field */ <output parameters> char *field; /* Address of the buffer where the converted string is returned */
RETURN VALUE
The dbatofld() function returns 0 for success. See the section on return code values for a detailed list of return codes.
DESCRIPTION
This function converts the string pointed to be ASCII to the numeric field format. The string must contain a valid floating point number. The number may be terminated by any character that cannot be part of a valid floating point number. This includes white space, punctuation other than periods, and characters other than e or E. The converted string is returned to the caller via the output parameter "field". Values of "width" and "decimal" must be the same as those used when creating the .DBF file. Those values can be obtained by The dbgetf() function.
EXAMPLE
The following example converts a floating point number 3245.876 in ASCII representation to the .DBF file numeric field format of 12 digits width and 3 decimal locations. The converted number is stored in "char field[13];".
#include "dbl.h" char field[13]; /* Record field location */ int rc; /* Return code */ rc = dbatofld("3245.876", 12, 3, field); if (rc == SUCCESS) printf("conversion successful\n"); else { printf("error number %d\n",rc); exit(1); }
SEE ALSO
dbcreat(), dbfield(), dbfldtoa(), dbgetf(), dbkeytoa(), dbstring(), dbstrcpy()