Public feed
#376635
#include <stdio.h> // for input output functions (printf/fprintf)
#include <stdlib.h> // 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,"<br>\n"); //add a "<br>" 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, "<html>\n<head>\n"); /* write the html */
fprintf(outfile, "<title> %s </title>\n", title); //write the <title> 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
}