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