Show convert-map.c syntax highlighted
#include <math.h>
#include <stdio.h>
struct map {
int node;
float x[3];
int point;
float angle;
};
int main(int argc, char **argv)
{
int count=0;
struct map nodes[100];
char input[8192];
int res;
while (1) {
if (fgets(input,8192,stdin) == NULL) {
break;
}
if (input[0] == '#') {
continue;
}
res = sscanf(input, "%d %f %f %f %d",
&(nodes[count].node),
&(nodes[count].x[0]),
&(nodes[count].x[1]),
&(nodes[count].x[2]),
&(nodes[count].point));
if (res == EOF) {
break;
}
if (res != 5) {
fprintf(stderr, "error .. %d", res);
continue;
}
count++;
}
/* ok, compute the angles.. */
int i,j;
for (i=0; i<count; i++) {
for (j=0; j<count; j++) {
if (nodes[i].point == nodes[j].node) {
nodes[i].angle = atan2(nodes[j].x[1] - nodes[i].x[1],
nodes[j].x[0] - nodes[i].x[0]);
nodes[i].angle = nodes[i].angle * 180.0 / M_PI;
}
}
printf("%d\t%f\t%f\t%f\t%f\n",
nodes[i].node,
nodes[i].x[0],
nodes[i].x[1],
nodes[i].x[2],
nodes[i].angle);
}
return 0;
}
See more files for this project here