Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <stdio.h>
  3.  
  4. const char hextable[] = "0123456789abcdef";
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.  
  9. FILE *fin;
  10. FILE *fout;
  11. unsigned i;
  12. int num;
  13.  
  14. if (argc != 3)
  15.         {
  16.         printf ("file2c v0.2 by O.Bogomaz (albom85@yandex.ru)\nfile2c.exe file.in file.out\n\n");
  17.         return -1;
  18.         }
  19.  
  20. fin = fopen (argv[1], "rb");
  21. fout = fopen (argv[2], "wt");
  22.  
  23. fprintf(fout, "char array[]= {");
  24.  
  25. for (i = 0;; i++)
  26.         {
  27.         if ( 0 == i%16)
  28.                 fprintf(fout, "\n");
  29.         num = getc(fin);
  30.         if (feof(fin))
  31.                 break;
  32.         fprintf (fout, "0x%c%c,", (int)hextable[(num >> 4)], (int)hextable[(num & 0x0f)]);
  33.         }
  34.  
  35. fprintf(fout, "\n };\n");
  36.  
  37. return 0;
  38. }
  39.