Meh, having some trouble with the beginning of the program. All I have so far is the code to read the data, and then print it, to verify it is working. But it doesn't work.
#include
#include
main()
{
const float pi=3.14159;
FILE *fRead;
char filename[20];
float x1, y1;
float x2, y2;
int i, numcirc;
float circlex[15], circley[15], radius[15];
fRead = fopen("file1.dat", "r");
if (fRead==NULL) {
printf("File unavailable\n");
return 1;
}
fscanf(fRead, "%f", x1);
fscanf(fRead, "%f", y1);
fscanf(fRead, "%f", x2);
fscanf(fRead, "%f", y2);
fscanf(fRead, "%d", numcirc);
if (numcirc>15) {
printf("too many circles, aborting\n");
return 1;
}
for(i=0; i fscanf(fRead, "%f%f%f", circlex[i], circley[i], radius[i]);
}
fclose(fRead);
printf("x1 is %f\n", x1);
printf("y1 is %f\n", y1);
printf("x2 is %f\n", x2);
printf("y2 is %f\n", y2);
printf("numcirc is %d\n", numcirc);
printf("circles:\n");
for(i=0; i printf("%f %f %f", circlex[i], circley[i], radius[i]);
}
printf("That's all the data I got/n");
return 0;
}
If the file doesn't exist, it prints "file unavailable" and exits, like I expected. But if the file does exist, all I get is "Bus error". Compiling and running on a Mac. Any ideas? I've never used file pointers or file streams before, so that's probably where the problem is.
Also, is there a way to get around setting the size of my arrays? I would rather just have radius[] be open, so I could process any number of circles. But declaring them without a size gives a syntax error.