#include <fstream>
#include <iostream>

using namespace std;
#ifdef NO_MAIN
extern "C" {
extern int bin2dec_main(int argc, char ** argv);
}
int bin2dec_main(int argc, char ** argv)
#else
int main(int argc, char ** argv)
#endif
{
   int rc = 0;
   if(argc != 3) {
      cerr << "usage: bin2dec <binary-input-file> <text-output-file>\n"; 
      return 1;
   }
   fstream fout(argv[2], ios::out | ios::trunc | ios::ate);
   fstream fin(argv[1], ios::in | ios::binary);
   if(!fin.fail() && !fout.fail()) {
      char ch;
      fin.read(&ch,sizeof(char));
      long count = 1;
      while(!fin.fail()) {
         fout << (int)ch << "," << flush;
         //cout << (int)ch << "," << flush;
         fin.read(&ch,sizeof(char));
         if((count % 5L) == 0) {
            fout << endl;
            //cout << endl;
         }
         count++;
      }
      //cout << endl;
      fin.close();
      fout.flush();
      fout.close();
   }
   else {
      cerr << "not found..." << endl;
      rc = 1;
   }
   return rc;
}
