View Full Version : reading old dos binary files

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

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

// reading contents... help here is needed

if(loop < sizeof fileBuffer)
fileBuffer[loop++] = (unsigned char)fgetc(inFile);
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.

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

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.

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