joeserhal
09-15-2008, 01:19 AM
Hey guys,
I'm trying to write a program that would read a dbase III file as input and make some changes according to the need of the user (delete a record, delete a field...). Anyways, what I am doing is the following:
1) reading the dbase III file
2) creating a hex dump out of it
3) reading the hex dump and making changes to the hex dump
now, what i need to do first is make sure that dump corresponds to one of dbase III file (the first byte represents the version of the dbase III file: it should be "03" )
I have wrote a test program that should make such checkings but it doesn't seem to work...:(
ERROR
------
http://img244.imageshack.us/img244/4159/errorre5.th.jpg (http://img244.imageshack.us/my.php?image=errorre5.jpg)
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
FILE *fd;
char ch;
char filename[20];
struct {
char version;
struct {
char yy;
char mm;
char dd; } modify;
int number_of_records ; /* 32 bits */
} header;
printf ("sizeof header = %d\n", sizeof(header) );
printf("Enter file name:");
scanf("%s",filename);
fd = fopen ( filename, "rb");
if ( fd == NULL )
{
printf ("Unable to open file %s\n", filename);
system ("pause");
exit (1);
}
/* read the first part of the header information */
/* and verify that it is a dbase III file */
fread ( &header, 1, sizeof ( header ), fd );
if ( header.version != 3 ) /* what about 0x83 */
{
printf ("not a dbase 3 file, found %x\n", header.version );
system ("pause");
exit (2);
}
printf ("Date last updated: %2.2d/%2.2d/%2.2d\n",header.modify.mm, header.modify.dd, header.modify.yy );
system ("pause");
fclose ( fd );
system ("pause");
return 0;
} /* end of main */
I have attached a sample hex dump of a dbase III file.
Anybody knows why this is not working???
I'm trying to write a program that would read a dbase III file as input and make some changes according to the need of the user (delete a record, delete a field...). Anyways, what I am doing is the following:
1) reading the dbase III file
2) creating a hex dump out of it
3) reading the hex dump and making changes to the hex dump
now, what i need to do first is make sure that dump corresponds to one of dbase III file (the first byte represents the version of the dbase III file: it should be "03" )
I have wrote a test program that should make such checkings but it doesn't seem to work...:(
ERROR
------
http://img244.imageshack.us/img244/4159/errorre5.th.jpg (http://img244.imageshack.us/my.php?image=errorre5.jpg)
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
FILE *fd;
char ch;
char filename[20];
struct {
char version;
struct {
char yy;
char mm;
char dd; } modify;
int number_of_records ; /* 32 bits */
} header;
printf ("sizeof header = %d\n", sizeof(header) );
printf("Enter file name:");
scanf("%s",filename);
fd = fopen ( filename, "rb");
if ( fd == NULL )
{
printf ("Unable to open file %s\n", filename);
system ("pause");
exit (1);
}
/* read the first part of the header information */
/* and verify that it is a dbase III file */
fread ( &header, 1, sizeof ( header ), fd );
if ( header.version != 3 ) /* what about 0x83 */
{
printf ("not a dbase 3 file, found %x\n", header.version );
system ("pause");
exit (2);
}
printf ("Date last updated: %2.2d/%2.2d/%2.2d\n",header.modify.mm, header.modify.dd, header.modify.yy );
system ("pause");
fclose ( fd );
system ("pause");
return 0;
} /* end of main */
I have attached a sample hex dump of a dbase III file.
Anybody knows why this is not working???