Messier Object %i

/******************************************************************/

/* Program[i]: m[i].c */

/* Created By: Guy “Smiley” McArthur ([email protected])*/

/* Purpose: Reads in Messier Catalog, prints out a HTML file for */

/* each object */

/******************************************************************/

#include

int main(void);

int i = 0, t = 0;

char file[11];

FILE *fp; /* m???.html */

FILE *in; /* data.txt */

struct MESSIER

{

int number;

int ngc;

char con[3];

int type;

char type_link[12];

int alpha;

float a_min;

int delta;

int d_min;

float mag;

float ly;

char description[30];

} m[111];

/********************************************************************/

int main(void)

{

char data[80];

char link1[10];

char link2[10];

char link3[10];

if((in = fopen(“data.txt”, “r”)) == NULL) return(0);

while(!feof(in))

{

++i;

fgets(data, 81, in);

sscanf(data, “%d,%d,%3c,%d,%d,%f,%d,%d,%f,%f”,&m[i].number,&m[i].ngc,m[i].con,&m[i].type,&m[i].alpha,&m[i].a_min,&m[i].delta,&m[i].d_min,&m[i].mag,&m[i].ly);

switch(m[i].type)

{

case(1):

sprintf(m[i].description,”Open Cluster”);

sprintf(m[i].type_link, “cluster.html”);

break;

case(2):

sprintf(m[i].description,”Globular Cluster”);

sprintf(m[i].type_link, “cluster.html”);

break;

case(3):

sprintf(m[i].description,”Planetary Nebula”);

sprintf(m[i].type_link, “nebula.html”);

break;

case(4):

sprintf(m[i].description,”Diffuse Nebula”);

sprintf(m[i].type_link, “nebula.html”);

break;

case(5):

sprintf(m[i].description,”Spiral Galaxy”);

sprintf(m[i].type_link, “galaxy.html”);

break;

case(6):

sprintf(m[i].description,”Elliptical Cluster”);

sprintf(m[i].type_link, “galaxy.html”);

break;

case(7):

sprintf(m[i].description, “Irregular Galaxy”);

sprintf(m[i].type_link, “galaxy.html”);

break;

case(8):

sprintf(m[i].description,”Double Star”);

sprintf(m[i].type_link, “cluster.html”);

break;

case(9):

sprintf(m[i].description,”Supernova Remnant”);

sprintf(m[i].type_link, “nebula.html”);

break;

}/* end switch */

}/* end while, end pre-loop */

for(i=1 ; i<111 ; i++) /* Main for loop *********************************/ { /* determine next galaxy, next nebula, next cluster*/ for(t = i+1; t<112 ; ++t) { /* Find Next Cluster */ if(m[t].type == 1 || m[t].type == 2 || m[t].type == 8) { sprintf(link1, "m%03i.html", t); break; } } for(t = i+1; t<112 ; ++t) { /* Find Next Nebula */ if(m[t].type == 3 || m[t].type == 4 || m[t].type == 9) { sprintf(link2, "m%03i.html", t); break; } } for(t = i+1; t<112 ; ++t) { /* Find Next Galaxy */ if(m[t].type == 5 || m[t].type == 6 || m[t].type == 7) { sprintf(link3, "m%03i.html", t); break; } } /* Determine File name */ sprintf(file, "m%03i.html", i); if((fp = fopen(file, "wt")) == NULL) { printf("Can't open file %s", file); return(0); } printf("Writing %sn", file); /* Write HTML */ fprintf(fp, "nnn", i); fprintf(fp, "n"); fprintf(fp, "

nt“, i);

fprintf(fp, “tM %in

nn””

Scroll to Top