-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtext2tiles.c
43 lines (37 loc) · 888 Bytes
/
text2tiles.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <ctype.h>
void main(int argc, char **argv) {
FILE *ifp;
FILE *ofp;
int address;
char ascii;
if (argc < 3) {
printf("Usage: %s [source ASCII file] [converted hex file]\n", argv[0]);
return;
}
ifp = fopen(argv[1], "r");
if (ifp == NULL) {
printf("Error opening %s for reading\n", argv[1]);
return;
}
ofp = fopen(argv[2], "w");
if (ofp == NULL) {
printf("Error opening %s for writing\n", argv[2]);
return;
}
ascii = fgetc(ifp);
while (ascii != EOF) {
if ((ascii >= '!') && (ascii <= 'Z')) {
fprintf(ofp, "%02x00 ", ascii);
} else if (ascii == ' ') {
fprintf(ofp, "0000 ");
} else if (ascii == '\n') {
fprintf(ofp, "\n");
}
ascii = fgetc(ifp);
}
fclose(ifp);
fclose(ofp);
}