Difference between revisions of "Dbfldtoa()"

From Recital Documentation Wiki
Jump to: navigation, search
 
Line 11: Line 11:
  
 
<input parameters>
 
<input parameters>
char *field; /* Field to be converted */
+
char *field; /* Field to be converted */
int width; /* Width of the field */
+
int width; /* Width of the field */
  
 
<output parameters>
 
<output parameters>
char *ascii; /* Address of the buffer where the converted ASCII string is returned */
+
char *ascii; /* Address of the buffer where the converted ASCII string is returned */
  
 
</code>
 
</code>
Line 29: Line 29:
 
This function converts a numeric field of a record containing a floating-point number to ASCII format.  RECITAL/Library functions manipulate records/fields as ASCII data, therefore functions like this and others which allow data conversion must be utilized.  The length of the resulting string equals the width of the field + 1, the string is null terminated.
 
This function converts a numeric field of a record containing a floating-point number to ASCII format.  RECITAL/Library functions manipulate records/fields as ASCII data, therefore functions like this and others which allow data conversion must be utilized.  The length of the resulting string equals the width of the field + 1, the string is null terminated.
  
NOTE: Make sure that the output character buffer is at least 1 byte longer than the "width" input parameter, since a NULL character is added to the output string.  The value of "width" must be the same as the value specified when creating the .DBF file.  If the value is forgotten, it can be obtained by calling The [[dbgetf()]] function.
+
NOTE: Make sure that the output character buffer is at least 1 byte longer than the "width" input parameter, since a NULL character is added to the output string.  The value of "width" must be the same as the value specified when creating the .DBF file.  If the value is forgotten, it can be obtained by calling the [[dbgetf()]] function.
  
  
Line 39: Line 39:
 
#include "dbl.h"
 
#include "dbl.h"
  
char record[100]; /* Record buffer */
+
char record[100]; /* Record buffer */
char ascii[11]; /* ASCII form of numeric field */
+
char ascii[11]; /* ASCII form of numeric field */
int rc; /* Return code */
+
int rc; /* Return code */
  
 
rc = dbfldtoa(record + 29, 10, ascii);
 
rc = dbfldtoa(record + 29, 10, ascii);
if (rc = = SUCCESS) printf("copy successful n");
+
if (rc = = SUCCESS) printf("copy successful \n");
 
else {
 
else {
printf("error message %d n", rc);
+
printf("error message %d \n", rc);
 
exit (1);
 
exit (1);
 
}
 
}

Revision as of 16:09, 3 April 2009

PURPOSE

convert numeric field to ASCII


SYNOPSIS

#include "dbl.h"
 
	int	dbfldtoa(field, width, ascii)
 
	<input parameters>
	char	*field;		/* Field to be converted */
	int	width;		/* Width of the field */
 
	<output parameters>
	char	*ascii;		/* Address of the buffer where the converted ASCII string is returned */


RETURN VALUE

The dbfldtoa() function returns 0 for success. See the section on return code values for a detailed list of return codes.


DESCRIPTION

This function converts a numeric field of a record containing a floating-point number to ASCII format. RECITAL/Library functions manipulate records/fields as ASCII data, therefore functions like this and others which allow data conversion must be utilized. The length of the resulting string equals the width of the field + 1, the string is null terminated.

NOTE: Make sure that the output character buffer is at least 1 byte longer than the "width" input parameter, since a NULL character is added to the output string. The value of "width" must be the same as the value specified when creating the .DBF file. If the value is forgotten, it can be obtained by calling the dbgetf() function.


EXAMPLE

This example converts a numeric field of 10 digits wide located at "record + 29" into an ASCII character string and stores the result in "char ascii[11]".

#include "dbl.h"
 
	char	record[100];	/* Record buffer */
	char	ascii[11];		/* ASCII form of numeric field */
	int	rc;			/* Return code */
 
	rc = dbfldtoa(record + 29, 10, ascii);
	if (rc = = SUCCESS) printf("copy successful \n");
	else {
		printf("error message %d \n", rc);
		exit (1);
	}


SEE ALSO

dbatofld(), dbcreat(), dbgetf(), dbkeytoa()