Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem with reading data from dbase III file (http://www.go4expert.com/forums/reading-data-dbase-iii-file-t13965/)

joeserhal 17Sep2008 08:37

Problem with reading data from dbase III file
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:


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");   

          fread ( buffer,d[j].field_length,1, infile );
          fwrite ( buffer,d[j].field_length,1, outfile );
          printf("%s ",buffer);   

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.... :sosp:


Any ideas?

xpi0t0s 17Sep2008 13:09

Re: Problem with reading data from dbase III file
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).

joeserhal 17Sep2008 14:18

Re: Problem with reading data from dbase III file

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??

xpi0t0s 18Sep2008 03:11

Re: Problem with reading data from dbase III file
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.

All times are GMT +5.5. The time now is 18:12.