////////////////////////////////////////////////////////////////////////////////
//Copyright (C) Aviral Mittal.
////////////////////////////////////////////////////////////////////////////////
// This program converts a binary file into a hex file.
// The input is any binary file such as song.mp3, and the o/p is corresponding
// hex file. with one byte per line e.t
//----
// ff
// fa
// 01
// 00
// .
// .
//----
////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
int main(int argc, char* argv[]){

  FILE *stream, *fopen();
  FILE *fi;//fi = fopen(argv[1], "r");;
  FILE *fo;
  unsigned char data; 
  char i;
  i = '0';

  if (argc == 3) {
    printf("ok\n");
    if ( (fi = fopen(argv[1],"r")) == NULL) {  
      printf("Can't open %s",argv[1]);
      exit(1);
    }
    else { //of if ( (fi = fopen(argv[1],"r")) == NULL)
      fo = fopen(argv[2], "w");
      while(feof(fi) == 0) {
        fread(&data, 1, 1, fi);
        if(data < 16) {
          fprintf(fo, "%c",i);
        }
        fprintf(fo, "%X\n",data);
      }//while(feof(fi) == 0)
      close(fo);
    }//else of if ( (fi = fopen(argv[1],"r")) == NULL)
  }// if (argc == 3)
  else {
    printf("Usage: bin2hex <input_binary_file> <output_hex_file>\n");
  }
}
