PC Review


Reply
Thread Tools Rate Thread

Can this be done using C#

 
 
Pete Kane
Guest
Posts: n/a
 
      14th May 2009
Hi All, I'm in the process of rewriting some very old C ( but still
useful ) database utilities and need some help with the type of "read"
function used in many of them. Is there an equivalent "read" function in
C# ? If I'm reading this correctly ( pun intended !) this read function
reads a numer of bytes directly into a struct

Regards




#include "stdafx.h"
#include "dbfhead.h"
#include "stdio.h"
#include "stdlib.h"
#include "fcntl.h"
#include "io.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

typedef struct
{
char dbf_id;
char last_update[3];
long last_rec;
short data_offset;
short rec_size;
char filler[20];
} DBF_HEAD;


int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
int handle;
DBF_HEAD dbf_head;


if(argv[1] == NULL)
{
printf("Usage dbfhead dbname, e.g. dbfhead c:\\data\\datfile.dbf\n");
exit(-1);
}

handle = open(argv[1],O_RDONLY|O_RAW);

if(read(handle,(char*)&dbf_head,sizeof(dbf_head)) !=sizeof(DBF_HEAD))
{
printf("\nRead Error\n");
exit(1);
}


printf("\n*** Database Header %s ***\n\n",argv[1]);
printf("\nDbf Id %d\n",dbf_head.dbf_id);
printf("Last Update %d %d
%ld\n\n",dbf_head.last_update[2],dbf_head.last_update[1],dbf_head.last_update[0]);
printf("Data Offset %d\n",dbf_head.data_offset);
printf("Record Size %d\n",dbf_head.rec_size);
printf("Number of Records %ld\n",dbf_head.last_rec);
close(handle);
return nRetCode;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:58 PM.