summaryrefslogtreecommitdiff
path: root/tools/bin2c.c
blob: a40e4310354bce0074634171e446ca69860c94b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * bin2c: converts a file to a C array of bytes
 */
 
#include <stdio.h>

int main(int argc, char *argv[])
{
	char *name = "data";
	int n = 0;
	int c;
	
	if(argc >= 2)
		name = argv[1];
		
	printf("unsigned char %s_array[] =\n{\n", name);
	
	while((c=getchar()) != EOF)
	{
		printf("%d, ", c);
		n++;
		
		if(!(n & 15))
			printf("\n");
	}
	
	printf("};\n");
	
	return 0;
}