rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define FILENAME "enterprise.txt"
char field[111] = "";
struct object {
char letter;
int x;
int y;
};
struct object objects[100];
int count = 0;
int main() {
FILE * fin = 0;
memset(objects,0,sizeof(objects));
fin = fopen(FILENAME, "r");
if (!fin) {
fprintf(stderr, "Could not open %s\n", FILENAME);
exit(-1);
}
int res = fread(field, 110,1,fin);
if (!res) {
fprintf(stderr, "Could not read in the field\n");
exit(-2);
}
fclose(fin);
field[110] = 0;
char * f1 = field;
int pos = 0;
size_t off = 0;
while (1) {
off = strspn(f1, ".\n");
pos = off+pos+1;
if (*(f1+off) == 0)
break;
printf("%c %d,%d\n", *(f1+off), pos/11,pos%11);
objects[count].letter = *(f1+off);
objects[count].y = pos/11;
objects[count].x = pos%11;
count++;
f1 += off+1;
}
int i,j;
printf("Count: %d\n", count);
for (i = 0; i < count; i++) {
for (j = i; j < count; j++) {
int x1=objects[i].x,
x2=objects[j].x,
y1=objects[i].y,
y2=objects[j].y;
printf("%c:%c dist:%.4f\n", objects[i].letter,objects[j].letter,
sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
}
return 0;
}