#include // for input output functions (printf/fprintf) #include // Your teacher included this on his website /* lab5 */ void makeHeader(FILE *outfile, char *title); // ANSI C prototype void finish(FILE *outfile); // ANSI C prototype int main() { FILE *out; //File Pointer int i, j; // for the factor table if ((out = fopen("myWebPage.html", "w")) == NULL) { // means open myWebPage.html in writing mode printf("Error Opening myWebPage.html"); // only if you couldn't open the file (rare) exit(1); //exits program early } makeHeader(out, "Factors"); //call to the function for(i = 1; i <= 16; i++) { // simple factoring; print 1 - 16, each on a newline fprintf(out, "%d| ", i); for(j = 1; j <= i; j++) { //inner loop finds the factors if((i % j) == 0) { //if there is no remainder j is a factor fprintf(out, "%d ", j); //print j to the file } } fprintf(out,"
\n"); //add a "
" and newline after each inner loop } finish(out); //function call fclose(out); // YOU HAVE TO DO THIS WHEN YOU FOPEN() SOMETHING return 0; } void makeHeader(FILE *outfile, char *title) { // function declaration fprintf(outfile, "\n\n"); /* write the html */ fprintf(outfile, " %s \n", title); //write the line fprintf(outfile, "</head>\n<body>\n"); //write those two lines } void finish(FILE *outfile) { fprintf(outfile, "</body>\n</html>\n"); //just append </body> and </html> to the end }