Difference between revisions of "Dbkeytoa()"

From Recital Documentation Wiki
Jump to: navigation, search
 
 
(4 intermediate revisions by one user not shown)
Line 11: Line 11:
  
 
<input parameters>
 
<input parameters>
char *key; /* Key to be converted */
+
char *key; /* Key to be converted */
char ascii[0]; /* Number of decimal places for numeric key */
+
char ascii[0]; /* Number of decimal places for numeric key */
char ascii[1]; /* Key type: 'D' – for DATE, 'N' – for NUMERIC */
+
char ascii[1]; /* Key type: 'D' – for DATE, 'N' – for NUMERIC */
  
 
<output parameters>
 
<output parameters>
char *ascii; /* Address of an ASCII string representing the converted key value */
+
char *ascii; /* Address of an ASCII string representing the converted key value */
 +
</code>
  
NOTE: "ascii" is used in the input and output parameter.
 
  
</code>
+
NOTE: "ascii" is used in the input and output parameter.
  
  
Line 36: Line 36:
  
 
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.
 
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.
 +
  
 
<code lang="c">
 
<code lang="c">
 
#include "dbl.h"
 
#include "dbl.h"
  
char key[8]; /* Key to be converted */
+
char key[8]; /* Key to be converted */
char ascii[64]; /* Buffer for converted key */
+
char ascii[64]; /* Buffer for converted key */
int rc; /* Return code */
+
int rc; /* Return code */
  
ascii[0] = 3; /* Specify number of decimal places */
+
ascii[0] = 3; /* Specify number of decimal places */
ascii[1] = 'N'; /* Indicate the key is NUMERIC */
+
ascii[1] = 'N'; /* Indicate the key is NUMERIC */
  
 
rc = dbkeytoa(key, ascii);
 
rc = dbkeytoa(key, ascii);
if (rc = = SUCCESS) printf("the key is '%s' n", ascii);
+
if (rc == SUCCESS) printf("the key is '%s' \n", ascii);
 
else {
 
else {
printf("error number %d n", rc);
+
printf("error number %d \n", rc);
 
exit (0);
 
exit (0);
 
}
 
}
 
</code>
 
</code>
 +
  
 
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.
 
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.
 +
  
 
<code lang="c">
 
<code lang="c">
 
#include "dbl.h"
 
#include "dbl.h"
  
char *ndx; /* .NDX file descriptor */
+
char *ndx; /* .NDX file descriptor */
char prevkey[8] /* Previous key buffer */
+
char prevkey[8] /* Previous key buffer */
long recno; /* Record no. associated with previous key */
+
long recno; /* Record no. associated with previous key */
char ascii[10]; /* Ascii string buffer */
+
char ascii[10]; /* Ascii string buffer */
int rc; /* Return code */
+
int rc; /* Return code */
ascii[1] = 'D'; /* Indicate the date key */
+
ascii[1] = 'D'; /* Indicate the date key */
  
  
 
rc = dbpkey(ndx, prevkey, &recno);
 
rc = dbpkey(ndx, prevkey, &recno);
if (rc = = SUCCESS){
+
if (rc == SUCCESS){
 
rc = dbkeytoa(prevkey, ascii);
 
rc = dbkeytoa(prevkey, ascii);
if (rc = = SUCCESS)
+
if (rc == SUCCESS)
printf("The previous key is %s n", ascii);
+
printf("The previous key is %s \n", ascii);
 
else{
 
else{
printf("error number %d n", rc);
+
printf("error number %d \n", rc);
 
exit (1);
 
exit (1);
 
}
 
}
{
+
}
  
 
</code>
 
</code>

Latest revision as of 13:36, 1 May 2009

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