/* text2html_modified_b.c
Author: Murray Saul
Date: April 8, 2008
Purpose: To read from a specified textfile and produce on the
terminal and store in specified output file valid html code
*/
#include
#define TAG_SIZE 3 + 1
#define TEXT_SIZE 1024 + 1
#define FILE_NAME_SIZE 256 + 1
#define ARRAY_SIZE 250
int getData(char tag[ARRAY_SIZE][TAG_SIZE], char text[ARRAY_SIZE][TEXT_SIZE]);
int printHtml (char tag[ARRAY_SIZE][TAG_SIZE], char text[ARRAY_SIZE][TEXT_SIZE],
int numberOfRecords);
int main(void)
{
int numberOfRecords, writeStatus;
char tag[ARRAY_SIZE][TAG_SIZE];
char text[ARRAY_SIZE][TEXT_SIZE];
numberOfRecords = getData(tag, text);
if ( numberOfRecords < 0 )
return 1;
writeStatus = printHtml(tag, text, numberOfRecords);
if (writeStatus)
return 0;
else
return 1;
} /* end of main program */
int getData(char tag[ARRAY_SIZE][TAG_SIZE], char text[ARRAY_SIZE][TEXT_SIZE])
{
int i = 0;
char inputFileName[FILE_NAME_SIZE];
FILE *fp_in;
printf ("Please enter input filename: ");
scanf ("%s", inputFileName);
fp_in = fopen(inputFileName, "r");
if ( fp_in == NULL )
{
printf ("Error: cannot open \"%s\" for reading\n\n", inputFileName);
return -1;
}
else
while ( fscanf(fp_in, "%[^;];%[^\n]\n", tag[i], text[i]) == 2 )
i++;
fclose(fp_in);
return i;
} /* end of getDate() */
int printHtml (char tag[ARRAY_SIZE][TAG_SIZE], char text[ARRAY_SIZE][TEXT_SIZE],
int numberOfRecords)
{
int i;
char outputFileName[FILE_NAME_SIZE];
FILE *fp_out;
printf ("Please enter output filename: ");
scanf ("%s", outputFileName);
fp_out = fopen (outputFileName, "w");
if ( fp_out == NULL )
{
printf ("Error: cannot open \"%s\" for reading\n\n", outputFileName);
return -1;
}
else
{
printf ("\n \n Change This Later\n \n \n");
for (i = 0; i < numberOfRecords; i++)
printf (" <%s>%s%s>\n", tag[i], text[i], tag[i]);
printf (" \n\n");
fprintf (fp_out,"\n \n Change This Later\n \n \n");
for (i = 0; i < numberOfRecords; i++)
fprintf (fp_out," <%s>%s%s>\n", tag[i], text[i], tag[i]);
fprintf (fp_out," \n\n");
fclose(fp_out);
return 1;
}
} /* end of printHtml() function */