diff --git a/lab24/files/out1.html b/lab24/files/out1.html
new file mode 100644
index 0000000..b2b2639
--- /dev/null
+++ b/lab24/files/out1.html
@@ -0,0 +1 @@
+
HTML DocumentAlice's Adventures in Wonderland
Lewis Carroll
Chapter I
DOWN THE RABBIT-HOLE
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book", thought Alice "without pictures or conversation?"
\ No newline at end of file
diff --git a/lab24/files/out2.html b/lab24/files/out2.html
new file mode 100644
index 0000000..409b2dd
--- /dev/null
+++ b/lab24/files/out2.html
@@ -0,0 +1 @@
+HTML DocumentAlice's Adventures in Wonderland
Lewis Carroll
Chapter I
DOWN THE RABBIT-HOLE
Alice was beginning to get very tired of sitting by her sister on the bank, and of having RABBIT nothing to do: once or twice she had peeped into the book her CARROLL sister was reading, but it had no carroll pictures or conversations in it, "and what is the use of a book", thought Alice "without pictures or conversation?"
\ No newline at end of file
diff --git a/lab24/files/text1.txt b/lab24/files/text1.txt
index f06ac82..28ea0ad 100644
--- a/lab24/files/text1.txt
+++ b/lab24/files/text1.txt
@@ -1,3 +1,4 @@
+Alice's Adventures in Wonderland
Lewis Carroll
diff --git a/lab24/files/text2.txt b/lab24/files/text2.txt
new file mode 100644
index 0000000..7a6d898
--- /dev/null
+++ b/lab24/files/text2.txt
@@ -0,0 +1,8 @@
+Alice's Adventures in Wonderland
+Lewis Carroll
+
+
+Chapter I
+DOWN THE RABBIT-HOLE
+
+Alice was beginning to get very tired of sitting by her sister on the bank, and of having RABBIT nothing to do: once or twice she had peeped into the book her CARROLL sister was reading, but it had no carroll pictures or conversations in it, "and what is the use of a book", thought Alice "without pictures or conversation?"
\ No newline at end of file
diff --git a/lab24/lab24.vcxproj b/lab24/lab24.vcxproj
index 70ba35b..ef1997f 100644
--- a/lab24/lab24.vcxproj
+++ b/lab24/lab24.vcxproj
@@ -129,6 +129,14 @@
+
+
+
+
+
+
+
+
diff --git a/lab24/lab24.vcxproj.filters b/lab24/lab24.vcxproj.filters
index 48814f7..224d2c9 100644
--- a/lab24/lab24.vcxproj.filters
+++ b/lab24/lab24.vcxproj.filters
@@ -19,4 +19,20 @@
Исходные файлы
+
+
+ Файлы ресурсов
+
+
+ Файлы ресурсов
+
+
+
+
+ Файлы ресурсов
+
+
+ Файлы ресурсов
+
+
\ No newline at end of file
diff --git a/lab24/main.c b/lab24/main.c
index 92a82e2..75ece00 100644
--- a/lab24/main.c
+++ b/lab24/main.c
@@ -1,19 +1,60 @@
+#define _CRT_SECURE_NO_WARNINGS
+
#include
#include
+#include
+
+#define BUFLEN 128
+
+int getNextDelim(FILE* file, int* token) {
+ int ch = getc(file);
+ if (ch == EOF) {
+ return 0;
+ }
+
+ if (isalnum(ch)) {
+ ungetc(ch, file);
+ return 0;
+ }
+
+ *token = ch;
+ return 1;
+}
+
+int getNextWord(FILE* file, char token[], int len) {
+ int ch;
+ int i = 0;
+ while ((ch = getc(file)) != EOF && (i < len - 1)) {
+ if (isalnum(ch)) {
+ token[i] = ch;
+ }
+ else {
+ break;
+ }
+ i += 1;
+ }
+ ungetc(ch, file);
+ token[i] = '\0';
+ if (i == 0) {
+ return 0;
+ }
+ else {
+ return 1;
+ }
+}
void task1() {
FILE* fin = fopen("files/text1.txt", "r");
if (fin == NULL) {
puts("File cannot be opened");
- return 0;
+ return;
}
- FILE* fout = fopen("files/out1.html", "r");
+ FILE* fout = fopen("files/out1.html", "w");
if (fin == NULL) {
puts("File cannot be opened");
- return 0;
+ return;
}
-
fprintf(fout, "");
fprintf(fout, "");
fprintf(fout, "");
@@ -34,12 +75,88 @@ void task1() {
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();
+ //task1();
+ task2();
return 0;
}