Man, what's with all those while(1) loops?
And you still haven't figured out this code posting have you?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define YES 1
#define NO 0 // not used
struct data {
char* text;
int bold, italic, underline;
};
void createPage ( struct data *array, int num );
int main ( void ) {
int response, i;
char buff[BUFSIZ];
struct data myStructArray[20];
// this loop in a function would be a good idea
for ( i = 0 ; i < 20 ; i++ ) {
printf( "Please enter a line of text (blank to exit): " );
fflush( stdout );
fgets( buff, BUFSIZ, stdin );
if ( strlen(buff) == 1 ) break;
myStructArray[i].text = malloc( strlen(buff)+1 ); // allocate space
strcpy( myStructArray[i].text, buff );
printf( "\nDo you want text to be bold?[1/0] " );
fflush( stdout );
fgets( buff, BUFSIZ, stdin );
sscanf( buff, "%d", &response );
myStructArray[i].bold = response;
printf( "\nDo you want text to be Italics?[1/0] " );
fflush( stdout );
fgets( buff, BUFSIZ, stdin );
sscanf( buff, "%d", &response );
myStructArray[i].italic = response;
printf( "\nDo you want text to be Underlined?[1/0] " );
fflush( stdout );
fgets( buff, BUFSIZ, stdin );
sscanf( buff, "%d", &response );
myStructArray[i].underline = response;
}
createPage( myStructArray, i );
return 0;
}
void createPage( struct data *a, int num ) {
int i;
FILE* outFile;
outFile = fopen( "phaseTwo.html","w" );
/* All HTML files must start with this tag. */
fprintf( outFile,"<html>\n" );
for ( i = 0 ; i < num ; i++, a++ ) {
if(a->bold == YES) {
fprintf( outFile,"<b>" );
}
if(a->italic == YES) {
fprintf( outFile,"<i>" );
}
if(a->underline == YES) {
fprintf( outFile,"<u>" );
}
/* Write to the file HTML representing a line of text. */
fprintf( outFile,"<p>" );
fprintf( outFile,"%s",a->text );
fprintf( outFile,"</p>\n" );
if(a->bold == YES) {
fprintf( outFile,"</b>\n" );
}
if(a->italic == YES) {
fprintf( outFile,"</i>\n" );
}
if(a->underline == YES) {
fprintf( outFile,"</u>\n" );
}
}
fprintf( outFile,"</html>\n" );
fclose( outFile );
}