Problem with reading data from dbase III file

Discussion in 'C' started by joeserhal, Sep 17, 2008.

  1. joeserhal

    joeserhal New Member

    Joined:
    Feb 13, 2008
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    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.... :sosp:

    [​IMG]


    Any ideas?
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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).
     
  3. joeserhal

    joeserhal New Member

    Joined:
    Feb 13, 2008
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    What do you mean...does are thumbnails, just click on them. Am I missing smthg out??
     
    Last edited: Sep 17, 2008
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice