#define _CRT_SECURE_NO_WARNINGS #include #include #include #include "../string_my/string_my.h" #define BUFLEN 128 void task1() { FILE* fin = fopen("files/text1.txt", "r"); if (fin == NULL) { puts("File cannot be opened"); return; } FILE* fout = fopen("files/out1.html", "w"); if (fin == NULL) { puts("File cannot be opened"); return; } fprintf(fout, ""); fprintf(fout, ""); fprintf(fout, ""); fprintf(fout, ""); fprintf(fout, "HTML Document"); fprintf(fout, ""); fprintf(fout, ""); char ch; while ((ch = getc(fin)) != EOF) { if (ch == '\n') { fprintf(fout, "
"); } else { putc(ch, fout); } } fprintf(fout, ""); fprintf(fout, ""); fclose(fin); fclose(fout); } void task2() { FILE* fin = fopen("files/text2.txt", "r"); if (fin == NULL) { puts("File cannot be opened"); return; } FILE* fout = fopen("files/out2.html", "w"); if (fout == NULL) { puts("File cannot be opened"); return; } fprintf(fout, ""); fprintf(fout, ""); fprintf(fout, ""); fprintf(fout, ""); fprintf(fout, "HTML Document"); fprintf(fout, ""); fprintf(fout, ""); char buf[BUFLEN]; char tmp[BUFLEN]; int ch; while (feof(fin) == 0 && ferror(fin) == 0) { while (getNextDelim(fin, &ch)) { if (ch == '\n') { fprintf(fout, "
"); } else { fprintf(fout, "%c", ch); } } if (getNextWord(fin, buf, BUFLEN)) { int isbold = 0; int isitalic = 0; int len = (int)strlen(buf); if (len >= 2 && buf[len-2] == buf[len-1]) { isbold = 1; } int count = 0; for (int i = 0; i < len; i++) { if (isupper(buf[i])) { count += 1; } } if (count == len) { isitalic = 1; } if (isbold) { strcpy(tmp, buf); sprintf(buf, "%s", tmp); } if (isitalic) { strcpy(tmp, buf); sprintf(buf, "%s", tmp); } fprintf(fout, "%s", buf); } } fprintf(fout, ""); fprintf(fout, ""); fclose(fin); fclose(fout); } int main() { //task1(); task2(); return 0; }