-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpconv.c
35 lines (28 loc) · 828 Bytes
/
pconv.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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define INPUT_BASE 16
const char* FNAME_INPUT = "plt_text.txt";
const char* FNAME_OUTPUT = "plt.bin";
int main(int argc, char** argv) {
FILE* input;
FILE* output;
uint32_t color;
char line[16];
input = fopen(FNAME_INPUT, "r");
if(!input || ferror(input)) {
printf("Unable to open %s for reading.\n", FNAME_INPUT);
return 1;
}
output = fopen(FNAME_OUTPUT, "wb");
if(!output || ferror(output)) {
printf("Unable to open %s for writing.\n", FNAME_OUTPUT);
return 1;
}
while(!(feof(input) || ferror(input) || ferror(output))) {
fgets(line, sizeof(line), input);
color = (uint32_t)strtol(line, NULL, INPUT_BASE);
fwrite(&color, sizeof(uint32_t), 1, output);
}
return ferror(input) || ferror(output);
}