PDA

View Full Version : reading old dos binary files



ronin
11-10-2001, 12:18 PM
Could someone help me with this code. My goal is to create a simple dos program that can read and display the contents of binary help files. I am not looking to create a hex editor or anything like that.

#include <stdio.h> // old c stuff
#include <string.h>

#define CRTWIDTH 80
#define CRTLENGTH 20

int main(int argc, char *argv[])
{
FILE *inFile = NULL;
char fileName[80];
int loop;
int lines;
unsigned char fileBuffer[CRTWIDTH -1];

if(argc == 1)
{
printf("\nUsage [drive]:\\directory\\filename.hlp");
printf("\n--> ");
gets(fileName);
}
else
{
strcpy(fileName,argv[1]);

// open... test file here fopen(fileName, "rb")

// reading contents... help here is needed

while(!feof(inFile))
{
if(loop < sizeof fileBuffer)
fileBuffer[loop++] = (unsigned char)fgetc(inFile);
else
{
for(loop = 0; loop <= sizeof fileBuffer; count++)
printf("%c", fileBuffer[loop]));
// this char isn't cutting it
// blah
}

This is returning the binary info but not the way in which a user can read it. any ideas on how to fix this would be greatly appreciated.

Salem
11-10-2001, 12:28 PM
If you were taking the simplistic approach - just printing all the printable characters, then


if ( isprint(fileBuffer[loop]) ) printf("%c", fileBuffer[loop]));


But the binary data will mean something, and understanding it will produce a better tool.
Eg, it could be
- pointers to other sections
- lengths of paragraphs
etc etc

ronin
11-10-2001, 12:33 PM
yes... yes... I'd like the better tool version :) How would I go about it, if I don't know the structure of how the data was written?

I tried the isprint, but it's not what I'm looking for.

ronin
11-10-2001, 12:43 PM
Hey, now that's alright. Thanks Salem!!