OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [twotasks-2/] [dump/] [dump.c] - Blame information for rev 272

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 hellwig
/*
2
 * dump.c -- dump a binary file as contents of a C array
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
 
11
int main(int argc, char *argv[]) {
12
  FILE *infile, *outfile;
13
  int c, n;
14
 
15
  if (argc != 3) {
16
    printf("Usage: %s <infile> <outfile>\n", argv[0]);
17
    return 1;
18
  }
19
  infile = fopen(argv[1], "rb");
20
  if (infile == NULL) {
21
    printf("Error: cannot open file '%s' for input\n", argv[1]);
22
    return 1;
23
  }
24
  outfile = fopen(argv[2], "wt");
25
  if (outfile == NULL) {
26
    printf("Error: cannot open file '%s' for output\n", argv[2]);
27
    return 1;
28
  }
29
  n = 0;
30
  while (1) {
31
    c = getc(infile);
32
    if (c == EOF) {
33
      break;
34
    }
35
    fprintf(outfile, "0x%02X, ", c);
36
    n++;
37
    if (n == 8) {
38
      n = 0;
39
      fprintf(outfile, "\n");
40
    }
41
  }
42
  if (n != 0) {
43
    fprintf(outfile, "\n");
44
  }
45
  fclose(infile);
46
  fclose(outfile);
47
  return 0;
48
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.