home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
412.lha
/
crabs
/
intergerize.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-29
|
963b
|
43 lines
/*
** This program filters a small file such that the output
** is the set of short ints required to describe the input
** NOTE the file must be a rectangle to work and no tabs
*/
#include <stdio.h>
char file[100][100];
int linelen, numlines;
main()
{
int i;
linelen = 0;
numlines = 0;
while (gets(&file[numlines][0]) != NULL && numlines < 99) {
if ((i = strlen(&file[numlines][0])) > linelen)
linelen = i;
numlines++;
}
for(i=0; i<numlines; i++) {
printf("%s0x%c%c%c%c",
!i ? "{ " : i%8 != 7 ? ", " : ",\n ",
conv(i,0), conv(i,4), conv(i,8), conv(i,12) );
}
printf(" };\n");
return 0;
}
conv(line, pos)
{
int i;
static char hex[] = "0123456789abcdef";
i = (file[line][pos] == '*') ? 8 : 0;
i += (file[line][pos + 1] == '*') ? 4 : 0;
i += (file[line][pos + 2] == '*') ? 2 : 0;
i += (file[line][pos + 3] == '*') ? 1 : 0;
return (hex[i]);
}