Problem with reading data from dbase III file

joeserhal's Avatar, Join Date: Feb 2008
Go4Expert Member
Hi there,

I'm trying to read data from a dbase III file, and copy it to a newly created dbase III file.

I've got everything working, I am able to read all the data from the dbf file (such as version #, # of records, length of header...., descriptors...), but I'm facing a problem with reading the data from the actual records...

This is where I think the problem is originating from:

Code:
for(i=0; i < header.number_of_records; i++)
{
   fread( &ch, 1, sizeof(ch), infile);  // this 
   fwrite( &ch, 1, sizeof(ch), outfile);
   
if(ch == 0x20) /* the current record is valid (i.e, it is not deleted, there is no '*' before it) */
     printf("\n\nRecord is valid\n");
if(ch == '*')
     printf("\n\nRecord is deleted\n");     

for(j=0;j<num_fields;j++)
     {
           fread ( buffer,d[j].field_length,1, infile );
           fwrite ( buffer,d[j].field_length,1, outfile );
           printf("%s ",buffer);    
     }
     //printf("\n");         
}
i think the problem is with buffer (which is a char *)...maybe initialization issue....

This is what I'm getting:

It's giving me the value of the 1st field in the dbf file (there are two fields) + the path of where the program is actually running from....




Any ideas?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
As with your other post you have SIZE and COUNT the wrong way round. Read the documentation for fread() and fwrite(); the order is buffer, SIZE (not count), COUNT (not size), stream. Your code uses parameters buffer, count (WRONG), size (WRONG), stream.

I'm not sure if that is the cause of the problem, if fread just reads size*count bytes and dumps it at the pointer then that shouldn't make any difference. However it may align the records to a 4-byte address, in which case you'll get 4x as much data as you want and each byte will be separated by 3 padding bytes (which still doesn't explain where the 0x20 comes from in your previous post, unless of course 0x20 is the padding byte).

Also, rather than posting virtually unreadable images of the error/output, it looks like it's in a DOS box so just use copy and paste to transfer the text content directly. System menu - Edit - Mark. Also useful is System menu - Properties - Options tab - QuickEdit mode which allows you to click and drag to make with the mouse rather than having to use the menu. (I also find other settings in that and other tabs useful, specifically Insert mode, buffer size(80*5000), window size(80*50), and you can set the values you like as defaults with System menu - Defaults).
0
joeserhal's Avatar, Join Date: Feb 2008
Go4Expert Member
Quote:
Originally Posted by xpi0t0s
Also, rather than posting virtually unreadable images of the error/output
What do you mean...does are thumbnails, just click on them. Am I missing smthg out??

Last edited by joeserhal; 17Sep2008 at 14:36..
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Did swapping size and count make any difference?

It's just easier to read the errors/output if it's there on the screen without having to fanny around with thumbnails and extra windows.