Dbkeytoa()

From Recital Documentation Wiki
Revision as of 10:28, 2 April 2009 by Yvonnemilne (Talk | contribs)

Jump to: navigation, search

PURPOSE

convert numeric/data key value to ASCII


SYNOPSIS

#include "dbl.h"
 
	int	dbkeytoa(key, ascii)
 
	<input parameters>
	char	*key;		/* Key to be converted				*/
	char	ascii[0];	/* Number of decimal places for numeric key	*/
	char	ascii[1];	/* Key type: 'D' – for DATE, 'N' – for NUMERIC	*/
 
	<output parameters>
	char	*ascii;		/* Address of an ASCII string representing the converted key value 	*/


NOTE: "ascii" is used in the input and output parameter.


RETURN VALUE

The dbkeytoa() function returns 0 for success, or < 0 if an error occurs. See the section on return code value for a detailed list of return codes.


DESCRIPTION

This function converts a key of type NUMERIC or DATE into a null terminated ASCII string. If the key is of NUMERIC type the user must pass the number of decimal places to the function via the parameter ascii[0]. The key type is specified in the parameter ascii[1]. Function returns an error if the specified type is neither NUMERIC ('N' or 'n') nor DATE ('D' or 'd'). This function is particular useful if the user wants to examine a numeric or date key obtained by the dbckey() or dbnkey() functions.


EXAMPLE

The first example converts an .NDX file numeric key stored in "char key[8]" to an ASCII string which is placed in "char ascii[64]". The converted ASCII string has a precision of 3 decimal places. The converted key is printed on standard output.


#include "dbl.h"
 
	char	key[8];		/* Key to be converted		*/
	char	ascii[64];	/* Buffer for converted key		*/
	int	rc;		/* Return code				*/
 
	ascii[0] = 3;		/* Specify number of decimal places	*/
	ascii[1] = 'N';		/* Indicate the key is NUMERIC	*/
 
	rc = dbkeytoa(key, ascii);
	if (rc = = SUCCESS) printf("the key is '%s' n", ascii);
	else {
		printf("error number %d n", rc);
		exit (0);
	}


The second example reads the previous date key from the .NDX file specified by "char *ndx;", converts it from the .NDX date format to the ASCII date format and prints the key on the standard output.


#include "dbl.h"
 
	char	*ndx;		/* .NDX file descriptor			*/
	char	prevkey[8]	/* Previous key buffer				*/
	long	recno; 		/* Record no. associated with previous key	*/
	char	ascii[10];	/* Ascii string buffer				*/
	int	rc;		/* Return code					*/
	ascii[1] = 'D';		/* Indicate the date key			*/
 
 
	rc = dbpkey(ndx, prevkey, &recno);
	if (rc = = SUCCESS){
		rc = dbkeytoa(prevkey, ascii);
		if (rc = = SUCCESS)
			printf("The previous key is %s n", ascii);
		else{
			printf("error number %d n", rc);
			exit (1);
		}
	}


SEE ALSO

dbatokey(), dbatofld(), dbfldtoa(), dbpkey()