Dbatokey()
From Recital Documentation Wiki
Revision as of 11:12, 2 April 2009 by Yvonnemilne (Talk | contribs)
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. <code lang="c"> #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,9long0 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.