A couple of other points about style:
1) You did this:
Code:
struct points {
int x;
int y;
};
typedef struct points Points;
struct circle {
Points center;
float radius;
};
typedef struct circle Circle;
Points pts[3];
Circle crs[3];
While typedef's are certainly allowed (and they even might save some typing), in this instance, I am not sure it gained you clarity. Although the names you used for the typedef's are basically saying what structure it is using, i.e, Points = struct points, and Circle = struct circle, in my opinion this is still not as easy to read as:
Code:
struct points {
int x;
int y;
};
struct circle {
struct points center;
double radius;
};
struct circle crs[POINTS];
By removing a bit of unecessary stuff, I also got it down in size by 4 lines total, and 9 characters less than your version.
2) Notice this:
Code:
#define POINTS 6
struct circle crs[POINTS];
I used your #define POINTS, as it seemed to be the number you were using for entries from your data file. By doing:
Code:
struct circle crs[3];
What do you think happens in the following bit of your storeData() function?:
Code:
for (i = 0; i < 6; i++) {
fgets(temp, 10, fdata);
//puts(temp);
tokenPtr = strtok(temp, " ");
a = atoi(tokenPtr);
crs[i].center.x = a;
3) You did this:
Code:
tokenPtr = strtok(temp, " ");
a = atoi(tokenPtr);
Be aware that strtok returns a pointer to the next token, or NULL if there are no more tokens. Assuming you get a NULL return from strtok (and you will if you add something to deal with the radius numbers), and then pass that on to atoi, what is that going to do with your program? (Hint: Think KABOOM!!) You need to check the return value of strtok for NULL (That applies for your call(s) to fgets as well!).
4) You did:
Code:
int i, k, j, a, b, c, d, e, f;
But you only used i, a, and b. Furthermore, why not give use some useful names (i is ok, because that is C idiom for loop counters, but a and b are not so good). How about:
Code:
int xcoord;
int ycoord;
double radius;