Dbatofld()

From Recital Documentation Wiki
Jump to: navigation, search

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()