Difference between revisions of "Dbatokey()"
Yvonnemilne  (Talk | contribs)  | 
				Yvonnemilne  (Talk | contribs)   | 
				||
| Line 12: | Line 12: | ||
	<input parameters>  | 	<input parameters>  | ||
	char 	*ascii;		/* ASCII string to be converted */  | 	char 	*ascii;		/* ASCII string to be converted */  | ||
| − | 	char	*key;		/* Key type: 'D' or 'd' is for a date key, 'N' or 'n' is for a numeric key	*/  | + | 	char	*key;		/* Key type: 'D' or 'd' is for a date key, 'N' or 'n' is for a numeric key */  | 
	<output parameters>  | 	<output parameters>  | ||
| Line 46: | Line 46: | ||
	char	*ndx;		/* .NDX file descriptor	*/  | 	char	*ndx;		/* .NDX file descriptor	*/  | ||
	int	rc;			/* Return code */  | 	int	rc;			/* Return code */  | ||
| − | 	char	key[8];		/* Numeric key location	*/  | + | 	char	key[8];		/* Numeric key location */  | 
| − | 	key[0] ='N';		/* Indicate numeric key	*/  | + | 	key[0] ='N';		/* Indicate numeric key */  | 
	rc = dbatokey("124.52", key);  | 	rc = dbatokey("124.52", key);  | ||
| Line 71: | Line 71: | ||
#include "dbl.h"  | #include "dbl.h"  | ||
| − | 	char	*ndx;		/* .NDX file descriptor	*/  | + | 	char	*ndx;		/* .NDX file descriptor */  | 
	int	rc;			/* Return code */  | 	int	rc;			/* Return code */  | ||
| − | 	char	key[8];		/* Numeric key location	*/  | + | 	char	key[8];		/* Numeric key location */  | 
	key[0] ='D';		/* Indicate date key */  | 	key[0] ='D';		/* Indicate date key */  | ||
Revision as of 15:29, 3 April 2009
PURPOSE
ASCII to index key value
SYNOPSIS
#include<dbl.h> int dbatokey(ascii, key) <input parameters> char *ascii; /* ASCII string to be converted */ char *key; /* Key type: 'D' or 'd' is for a date key, 'N' or 'n' is for a numeric key */ <output parameters> char *key; /* Address of the buffer where converted key is returned, thus "key" serves as both the input and output parameter */
RETURN VALUE
The dbatokey() 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 by ascii to the .NDX file key format. The input ASCII string should represent either a valid floating point number or a date in the following format:-
YYYYMMDD YYYY - Year: '1900' through '2999' MM - Month: '01' through '12' DD - Day: '01' through '28'/'29'/'30'/'31'
EXAMPLE
This example converts the ASCII string "124.52" into the .NDX file key format and adds the numeric key to the index specified by "char *ndx;" with associated record number, 15.
#include "dbl.h" char *ndx; /* .NDX file descriptor */ int rc; /* Return code */ char key[8]; /* Numeric key location */ key[0] ='N'; /* Indicate numeric key */ rc = dbatokey("124.52", key); if (rc = = SUCCESS) { if (dbakey(ndx,key,(long)15) printf("Key added \n"); else { printf("Error number %\n",rc); exit(1); } } else { printf("Error number %d \n", rc); exit (1); }
This example converts a date, 19680408 (April 8, 1968) in ASCII representation into .NDX file key format and adds the new key to the specified .NDX file with associated record number, 420.
#include "dbl.h" char *ndx; /* .NDX file descriptor */ int rc; /* Return code */ char key[8]; /* Numeric key location */ key[0] ='D'; /* Indicate date key */ rc = dbatokey("19680408",key); if (rc = = SUCCESS) { if (dbakey(ndx,key,(long) 420) && rc= = SUCCESS) Printf("Key added \n"); Else { Printf("Error number %d \n", rc); Exit(1); } } else { printf("Error number %d \n", rc); exit (1); }
NOTE:  The buffer to hold the converted key value ("key" in our examples) must be at least eight bytes long.