Difference between revisions of "Dbatokey()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
Line 11: | Line 11: | ||
<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> | ||
− | char *key; /* Address of the buffer where converted key is returned, thus "key" serves as both the input and output parameter */ | + | char *key; /* Address of the buffer where converted key is returned, thus "key" serves as both the input and output parameter */ |
</code> | </code> | ||
Line 45: | Line 45: | ||
char *ndx; /* .NDX file descriptor */ | char *ndx; /* .NDX file descriptor */ | ||
− | int rc; | + | int rc; /* Return code */ |
char key[8]; /* Numeric key location */ | char key[8]; /* Numeric key location */ | ||
Line 52: | Line 52: | ||
rc = dbatokey("124.52", key); | rc = dbatokey("124.52", key); | ||
if (rc = = SUCCESS) { | if (rc = = SUCCESS) { | ||
− | if (dbakey(ndx,key,(long)15) printf("Key added n"); | + | if (dbakey(ndx,key,(long)15) printf("Key added \n"); |
else { | else { | ||
− | printf("Error number %n",rc); | + | printf("Error number %\n",rc); |
exit(1); | exit(1); | ||
} | } | ||
} else { | } else { | ||
− | printf("Error number %d n", rc); | + | printf("Error number %d \n", rc); |
exit (1); | exit (1); | ||
} | } | ||
Line 72: | Line 72: | ||
char *ndx; /* .NDX file descriptor */ | char *ndx; /* .NDX file descriptor */ | ||
− | int rc; | + | 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 */ |
rc = dbatokey("19680408",key); | rc = dbatokey("19680408",key); | ||
if (rc = = SUCCESS) { | if (rc = = SUCCESS) { | ||
− | if (dbakey(ndx,key, | + | if (dbakey(ndx,key,(long) 420) && rc= = SUCCESS) |
− | Printf("Key added n"); | + | Printf("Key added \n"); |
Else { | Else { | ||
− | Printf("Error number %d n", rc); | + | Printf("Error number %d \n", rc); |
Exit(1); | Exit(1); | ||
} | } | ||
} else { | } else { | ||
− | printf("Error number %d n", rc); | + | printf("Error number %d \n", rc); |
exit (1); | exit (1); | ||
} | } |
Revision as of 15:27, 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.