Difference between revisions of "Dbatokey()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
(3 intermediate revisions by one user not shown) | |||
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 29: | Line 29: | ||
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:- | 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' | + | |
+ | <pre> | ||
+ | YYYYMMDD YYYY - Year: '1900' through '2999' | ||
MM - Month: '01' through '12' | MM - Month: '01' through '12' | ||
DD - Day: '01' through '28'/'29'/'30'/'31' | DD - Day: '01' through '28'/'29'/'30'/'31' | ||
+ | </pre> | ||
+ | |||
==EXAMPLE== | ==EXAMPLE== | ||
Line 41: | 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 */ |
− | key[0] ='N'; /* Indicate numeric key */ | + | key[0] ='N'; /* Indicate numeric key */ |
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); | ||
} | } | ||
+ | |||
+ | </code> | ||
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. | 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"> | <code lang="c"> | ||
#include "dbl.h" | #include "dbl.h" | ||
− | 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 { | |
− | 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); | ||
} | } | ||
+ | </code> | ||
− | |||
− | + | NOTE: The buffer to hold the converted key value ("key" in our examples) must be at least eight bytes long. | |
Latest revision as of 11:24, 1 May 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.