-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconvertmap.cpp
More file actions
46 lines (37 loc) · 827 Bytes
/
convertmap.cpp
File metadata and controls
46 lines (37 loc) · 827 Bytes
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
44
45
46
#include <stdio.h>
char shorten_num(double);
main(int argc, char *argv[])
{
double numin;
FILE *infile, *outfile;
int ix;
char buffer[80];
infile = fopen(argv[1], "r");
outfile = fopen(argv[2], "w");
for(ix = 1; ix <= 6; ix++) {
fgets(buffer, 81, infile);
fputs(buffer, outfile);
}
while(fscanf(infile, "%lf", &numin) != EOF) {
fprintf(outfile, "%c\n", shorten_num(numin));
}
fclose(infile);
fclose(outfile);
return 0;
}
char shorten_num(double num)
{
/**** MANIPULATION CODE ****/
char numout;
if (num == 0.){
numout = 0;
} else if ((-12.8 < num) && (num < 0.)) {
numout = num * 10.;
} else if ((0. < num) && (num < 1280.)) {
numout = num / 10.;
} else if (num >= 1280.)
numout = 127;
else
numout = -128;
return numout;
}