How do i Read .DBF in C++

Dear everybody,

I want to open a .DBF file in C++, and search in it. Does anyone know how to do that or has a proper guide.

Regards, Bram Kools
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


.DBF is standard disk file and you may open it by standard low level C functions. DBF data have specific format which is known so you may even look for specific value in specific column. If you need to read memo fields also, they are in another file.

Third party libraries exist, e.g. this one

If you decide to read DBF yourself then the structure is following (if you need better formatting then look into Visual FoxPro help - the source for this info):

Table Header Record Structure
Byte offset Description
0 File type:
0x02 FoxBASE
0x03 FoxBASE+/Dbase III plus, no memo
0x30 Visual FoxPro
0x31 Visual FoxPro, autoincrement enabled
0x43 dBASE IV SQL table files, no memo
0x63 dBASE IV SQL system files, no memo
0x83 FoxBASE+/dBASE III PLUS, with memo
0x8B dBASE IV with memo
0xCB dBASE IV SQL table files, with memo
0xF5 FoxPro 2.x (or earlier) with memo
1 - 3 Last update (YYMMDD)
4  7 Number of records in file
8  9 Position of first data record
10  11 Length of one data record, including delete flag
12  27 Reserved
28 Table flags:
0x01 file has a structural .cdx
0x02 file has a Memo field
0x04 file is a database (.dbc)
This byte can contain the sum of any of the above values. For example, the value 0x03 indicates the table has a structural .cdx and a Memo field.
29 Code page mark
30  31 Reserved, contains 0x00
32  n Field subrecords
The number of fields determines the number of field subrecords. One field subrecord exists for each field in the table.
n+1 Header record terminator (0x0D)
n+2 to n+264 A 263-byte range that contains the backlink, which is the relative path of an associated database (.dbc) file, information. If the first byte is 0x00, the file is not associated with a database. Therefore, database files always contain 0x00.

Field Subrecords Structure
Byte offset Description 0  10 Field name with a maximum of 10 characters. If less than 10, it is padded with null characters (0x00). 11 Field type:
C      Character
Y      Currency
N      Numeric
F      Float
D      Date
T      DateTime
B      Double
I      Integer
L      Logical
M    Memo
G    General
C      Character (binary)
M      Memo (binary)
P      Picture 12  15 Displacement of field in record 16 Length of field (in bytes) 17 Number of decimal places 18 Field flags:
0x01   System Column (not visible to user)
0x02   Column can store null values
0x04   Binary column (for CHAR and MEMO only)
0x06   (0x02+0x04) When a field is NULL and binary (Integer, Currency, and Character/Memo fields)
0x0C   Column is autoincrementing 19 - 22 Value of autoincrement Next value 23 Value of autoincrement Step value 24  31 Reserved

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hmm, after switching to Rich Text and back the formatting is horrible...

So, if you need the DBF format, it is better to look at

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.