DlFieldGetN - demographics_library - 2024.01

Demographics Library Reference for Windows and UNIX

Product type
Software
Portfolio
Locate
Product family
GeoStan Geocoding Suite
Product
GeoStan Geocoding Suite > Demographics Library
Version
2024.01
Language
English
Product name
Demographics Library
Title
Demographics Library Reference for Windows and UNIX
Copyright
2024
First publish date
1994
Last updated
2024-05-17
Published on
2024-05-17T02:16:20.391253

Returns handle for numerically-specified field.

Syntax

DlFieldId DlFieldGetN (DlFileId hfile, intl fnum)

Arguments

hfile

Handle to file object, as returned by DlFileOpen. Input

fnum

Zero-based field number. Input

Return Value

Returns handle to specified field if successful, else NULL.

Notes

Use DlFileNumFields to retrieve the number of fields in a data file. With this information, you can specify a loop using DlFieldGetN to return the handles for each field in the data file. Alternatively, you can retrieve the handle for a specific field, if you know the field number. This is useful if you don't know the field names in the .DLD file.

See Also

DlFileNumFields, DlFieldGet, DlFieldGetAttribute

Example

// This function determines how many fields there are,
// then loops through all of them, outputting their names.
        ​
void ListFields(DlId dl, DlFileId idFile)
{
// Number of fields in the file, and a counter for the loop
intl lNumFields, lCount;
        ​
// ID that will be used to retrieve each field name.
DlFieldId idField;
char buffer[256];
        ​
lNumFields = DlFileNumFields(idFile);
        ​
// Here we get the number of fields.
 if (lNumFields < 1)
  {
  printf("\nDlFileNumFields returned less than 1.\n");
        ​
// Error if the return was invalid.
  ShowError(dl);
  }
 else
  {
  printf("\n");
  for (lCount = 0; lCount < lNumFields; lCount++)
// Now loop through all the fields (zero based).
   {
// Set idField to the current field number
   idField = DlFieldGetN(idFile, lCount);
        ​
// Make sure it was set, print an error if not.
 if (!idField)
  {
  printf("DlFieldGetN failed to retrieve field number %d.\n", lCount);
  ShowError(dl);
  break;
}
        ​
// Get the field name and print it.
  DlFieldGetAttribute(idField, DlName, buffer,
  sizeof(buffer));
  printf("%d: %s\n", lCount, buffer);
        ​
// If LINES_PER_PAGE lines have been printed, then pause until return is pressed so the user can read 
// what was the output.
        ​
  if (!((lCount + 1) % LINES_PER_PAGE))
   {
   printf("<more>");
   gets(buffer);
   }
  }
 }
 printf("\n");
}