mirror of
https://github.com/Kaehvaman/OAIP.git
synced 2025-01-30 16:58:26 +04:00
finish lab24
This commit is contained in:
parent
a1c30adacf
commit
c111094d0e
1
lab24/files/out1.html
Normal file
1
lab24/files/out1.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta http - equiv = "Content-Type" content = "text/html; charset=utf-8" /><title>HTML Document</title></head><body>Alice's Adventures in Wonderland<br>Lewis Carroll<br><br><br>Chapter I<br>DOWN THE RABBIT-HOLE<br><br>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?"</body></html>
|
1
lab24/files/out2.html
Normal file
1
lab24/files/out2.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta http - equiv = "Content-Type" content = "text/html; charset=utf-8" /><title>HTML Document</title></head><body>Alice's Adventures in Wonderland<br>Lewis <b>Carroll</b><br><br><br>Chapter <i>I</i><br><i>DOWN</i> <i>THE</i> <i>RABBIT</i>-<i>HOLE</i><br><br>Alice was beginning to get very tired of sitting by her sister on the bank, and of having <i>RABBIT</i> nothing to do: once or twice she had peeped into the book her <i><b>CARROLL</b></i> sister was reading, but it had no <b>carroll</b> pictures or conversations in it, "and what is the use of a book", thought Alice "without pictures or conversation?"</body></html>
|
@ -1,3 +1,4 @@
|
|||||||
|
Alice's Adventures in Wonderland
|
||||||
Lewis Carroll
|
Lewis Carroll
|
||||||
|
|
||||||
|
|
||||||
|
8
lab24/files/text2.txt
Normal file
8
lab24/files/text2.txt
Normal file
@ -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?"
|
@ -129,6 +129,14 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="files\out1.html" />
|
||||||
|
<None Include="files\out2.html" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="files\text1.txt" />
|
||||||
|
<Text Include="files\text2.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -19,4 +19,20 @@
|
|||||||
<Filter>Исходные файлы</Filter>
|
<Filter>Исходные файлы</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="files\out1.html">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="files\out2.html">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="files\text1.txt">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</Text>
|
||||||
|
<Text Include="files\text2.txt">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</Text>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
127
lab24/main.c
127
lab24/main.c
@ -1,19 +1,60 @@
|
|||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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() {
|
void task1() {
|
||||||
FILE* fin = fopen("files/text1.txt", "r");
|
FILE* fin = fopen("files/text1.txt", "r");
|
||||||
if (fin == NULL) {
|
if (fin == NULL) {
|
||||||
puts("File cannot be opened");
|
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) {
|
if (fin == NULL) {
|
||||||
puts("File cannot be opened");
|
puts("File cannot be opened");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fprintf(fout, "<!DOCTYPE html>");
|
fprintf(fout, "<!DOCTYPE html>");
|
||||||
fprintf(fout, "<html>");
|
fprintf(fout, "<html>");
|
||||||
fprintf(fout, "<head>");
|
fprintf(fout, "<head>");
|
||||||
@ -34,12 +75,88 @@ void task1() {
|
|||||||
|
|
||||||
fprintf(fout, "</body>");
|
fprintf(fout, "</body>");
|
||||||
fprintf(fout, "</html>");
|
fprintf(fout, "</html>");
|
||||||
|
|
||||||
|
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, "<!DOCTYPE html>");
|
||||||
|
fprintf(fout, "<html>");
|
||||||
|
fprintf(fout, "<head>");
|
||||||
|
fprintf(fout, "<meta http - equiv = \"Content-Type\" content = \"text/html; charset=utf-8\" />");
|
||||||
|
fprintf(fout, "<title>HTML Document</title>");
|
||||||
|
fprintf(fout, "</head>");
|
||||||
|
fprintf(fout, "<body>");
|
||||||
|
|
||||||
|
char buf[BUFLEN];
|
||||||
|
char tmp[BUFLEN];
|
||||||
|
int ch;
|
||||||
|
while (feof(fin) == 0 && ferror(fin) == 0) {
|
||||||
|
while (getNextDelim(fin, &ch)) {
|
||||||
|
if (ch == '\n') {
|
||||||
|
fprintf(fout, "<br>");
|
||||||
|
}
|
||||||
|
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, "<b>%s</b>", tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isitalic) {
|
||||||
|
strcpy(tmp, buf);
|
||||||
|
sprintf(buf, "<i>%s</i>", tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fout, "%s", buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fout, "</body>");
|
||||||
|
fprintf(fout, "</html>");
|
||||||
|
|
||||||
|
fclose(fin);
|
||||||
|
fclose(fout);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
task1();
|
//task1();
|
||||||
|
task2();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user