home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / database / paradox / struct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-01  |  1.6 KB  |  43 lines

  1. /* Program to display Paradox table fields and their types */
  2. /* By Peter M. Jagielski, Borland International */
  3. /* Make sure the Turbo C project file for STRUCT.C contains the 2 lines:
  4.                             STRUCT.C
  5.                             TABLETS.LIB                                  */
  6.  
  7. #include <stdio.h>
  8. #include <table.h>
  9.  
  10. main(argc,argv)
  11.   unsigned int argc;                     /* number of command line parameters */
  12.   char *argv[];                                                  /* file name */
  13.   {
  14.     TABLE *tableptr;                            /* pointer to structure TABLE */
  15.     unsigned int numfields,i;
  16.     char fieldname[25],fieldtype[4];
  17.  
  18.     if (argc == 1)                                  /* if not table specified */
  19.       {
  20.         puts("Syntax: STRUCT <tablename>");
  21.         exit(0);
  22.       }
  23.  
  24.     if ((tableptr = (TABLE *) tOpen(argv[1])) == NULL)     /* if table exists */
  25.       {
  26.         printf("Table \"%s\" doesn't exist",argv[1]);
  27.         exit(0);
  28.       }
  29.  
  30.     numfields = tNumFlds(tableptr);                   /* get number of fields */
  31.     printf("Table \"%s\" has %d fields:\n",argv[1],numfields);
  32.     puts("Field Type         Field Name");
  33.     puts("----------  -------------------------");
  34.     for (i = 1; i <= numfields; i++)
  35.       {
  36.         tFldName(tableptr,i,fieldname);                  /* get name of field */
  37.         tFldType(tableptr,i,fieldtype);                     /* get field type */
  38.         printf("  %4s      %s\n",fieldtype,fieldname);
  39.       }
  40.     tClose(tableptr);                                 /* close the table/file */
  41.   }
  42.  
  43.