Hello,
First thanks to all who have helped me get to this point.
I have a general question on how to tackle this section of problem. I need to read in a response from user (from 1 to 7) to determine the size of font to use in the text held in the structure array. Understand how to do a normal "scanf("%d", &fresponse) but not sure how to set it up. See the code below for a better understanding of problem....I need to read in response on size of text, apply it to the particular structure array of text then in the function apply it to the various fonts of 1 to 7:
#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, font;
};
void createPage ( struct data *array, int num);
int main ( void ) {
int response, i, fresponse;
char buff[BUFSIZ];
struct data myStructArray[80];
// this loop in a function would be a good idea
for ( i = 0 ; i < 80 ; i++ ) {
printf( "Please enter a line of text ('$' to exit): " );
fflush( stdout );
fgets( buff, BUFSIZ, stdin );
//This checks to see if the user wants to end program //
if ( buff[0] == '$' )
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;
printf( "\nDo you size font do you wish to use?[1-7] " );
fflush( stdout );
fgets( buff, BUFSIZ, stdin );
sscanf( buff, "%d", &fresponse );
myStructArray[i].font = fresponse;
}
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>" );
}
if(a->font == 1) {
fprintf( outFile,"<FONT SIZE = 1" );
}
//First attempt//
// fprintf( outFile,"<FONT SIZE = ", &fr );
/* 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" );
}
if(a->font== 1) {
fprintf( outFile,"</font>\n" );
}
}
fprintf( outFile,"</html>\n" );
fclose( outFile );
}