/* text2html_modified_a.c
Author: Murray Saul
Date: April 8, 2008
Purpose: To read from a textfile and produce on the
terminal and a file valid html code
*/
#include
#define TAG_SIZE 3 + 1
#define FILE_NAME_SIZE 256 + 1
#define TEXT_SIZE 1024 + 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;
int file_write_status;
char tag[ARRAY_SIZE][TAG_SIZE];
char text[ARRAY_SIZE][TEXT_SIZE];
numberOfRecords = getData(tag, text);
if ( numberOfRecords == -1 )
return 1;
else
{
file_write_status = printHtml(tag, text, numberOfRecords);
if (file_write_status)
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 filename[FILE_NAME_SIZE];
FILE *fp_in;
printf ("Please enter input file: ");
scanf ("%s", filename);
fp_in = fopen(filename, "r");
if ( fp_in == NULL)
{
printf ("Error: Cannot open \"%s\" for reading\n\n", filename);
return -1;
}
else
while ( fscanf(fp_in, "%[^;];%[^\n]\n", tag[i], text[i]) == 2)
i++;
fclose(fp_in);
return i;
} /* end of getData() function */
int printHtml (char tag[ARRAY_SIZE][TAG_SIZE], char text[ARRAY_SIZE][TEXT_SIZE],
int numberOfRecords)
{
int i;
char outputfile[FILE_NAME_SIZE];
FILE *fp_out;
printf ("Please enter output file: ");
scanf ("%s", outputfile);
fp_out = fopen(outputfile, "w");
if ( fp_out == NULL)
{
printf ("Error: Cannot open \"%s\" for writing\n\n", outputfile);
return -1;
}
else
{
printf ("\n \n Change this Later\n \n\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 \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 */