home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cl5sr386.zip / GO32 / BIN2BYTE.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  652b  |  33 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <sys/stat.h>
  4.  
  5. main(int argc, char **argv)
  6. {
  7.   int f = open(argv[1], O_RDONLY|O_BINARY);
  8.   FILE *of = fopen(argv[3], "w");
  9.   unsigned char buf[4096];
  10.   int rbytes;
  11.   int col=0, i;
  12.   if (argc < 4)
  13.   {
  14.     printf("usage: bin2byte infile symname outfile\n");
  15.     exit(1);
  16.   }
  17.   fprintf(of, "unsigned char %s[] = {\n", argv[2]);
  18.   while ((rbytes = read(f, buf, 4096)) > 0)
  19.   {
  20.     for (i=0; i<rbytes; i++)
  21.     {
  22.       fprintf(of, "%d,", buf[i]);
  23.       if (col++ == 32)
  24.       {
  25.         fprintf(of, "\n");
  26.         col = 0;
  27.       }
  28.     }
  29.   }
  30.   fprintf(of, "};\n");
  31.   fclose(of);
  32. }
  33.