/* This is a working version of the stars program that is in the book. It deals correctly with data input, and gets things a little bit organized, but it doesn't do any useful calculations. */ #include #include #define DATAFILE "/magellan/users1/math/wtaylor/stars.data" /* Field widths in the database */ #define RA_WIDTH 6 #define DECL_WIDTH 5 #define MAG_WIDTH 3 #define TYPE_WIDTH 6 #define CONSTELLATION_WIDTH 3 /* Data that will be taken from the data base for each star in turn: */ double ra_rads, decl_rads, magnitude; char name[55]; char type[TYPE_WIDTH+1], constellation[CONSTELLATION_WIDTH+1]; main() { FILE *fp_in; /* FILE *fopen(); */ char dataline[100]; int N, i, Q, load(), display(); void error_1(), error_2(), label_picture(), get_user_data(); get_user_data(); fp_in = fopen(DATAFILE, "r"); N=0; while (1) { for (i=0; i<100; i++) dataline[i]=0; Q = fscanf(fp_in,"%[^\n]\n",dataline); if (Q <= 0) {error_1(); break;} Q = load(dataline); if (Q <= 0) {error_2(); break;} display(); N++; } fclose(fp_in); label_picture(); } /* END of MAIN */ int load(dataline) char dataline[100]; { int i, N, Q; double ra_hours, ra_minutes, ra_seconds; double decl_degrees, decl_minutes, decl_sign; double u; char ra[RA_WIDTH], decl[DECL_WIDTH], mag[MAG_WIDTH]; if (strlen(dataline)