Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Windows file in/out skeleton...

Status
Not open for further replies.

davorin

Advanced Member level 3
Advanced Member level 3
Joined
Jun 7, 2003
Messages
901
Helped
11
Reputation
22
Reaction score
4
Trophy points
1,298
Location
Switzerland
Activity points
7,349
Is somebody aware of a C skeleton for Windows to be used as a simple file conversion utility?

Basically need to read in binary ROM images and convert them to a special text file...
 

Winhex can do the conversion from BIN to Text, it can even read intel hex file and motorola hex file.
 

How about this bare-bones binary-to-hex command-line utility?

Code:
#include <stdio.h>

int main(int argc, char *argv[])
{
  FILE *fin, *fout;
  int c;

  if (argc != 3)
  {
    printf("Specify binary input file and hex output file.\n");
    return 1;
  }

  if (!(fin = fopen(argv[1], "rb")))
  {
    printf("Can't open input file: %s\n", argv[1]);
    return 1;
  }

  if (!(fout = fopen(argv[2], "w")))
  {
    printf("Can't open output file: %s\n", argv[2]);
    fclose(fin);
    return 1;
  }

  while ((c = fgetc(fin)) != EOF)
    fprintf(fout, "%02X ", c);
  fclose(fout);
  fclose(fin);
  return 0;
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top