Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Лаб. работа №11, вариант B
- #include "stdafx.h"
- #include <string.h>
- #include <Windows.h>
- const int N = 255;
- void StartHtml(FILE* html_file, char title[])
- {
- fputs("<HTML><HEAD><TITLE>", html_file);
- fputs(title, html_file);
- fputs("</TITLE></HEAD><BODY><H1>", html_file);
- fputs(title, html_file);
- fputs("</H1><BR>", html_file);
- }
- void EndHtml(FILE* html_file)
- {
- fputs("</BODY></HTML>", html_file);
- }
- char* NewStr(char s[])
- {
- char tmp[2 * N] = "";
- int i = 0;
- char word[N] = "";
- int k = 0;
- bool isTargetWord = false;
- while (s[i] != '\0')
- {
- if (s[i] == ' ' || s[i] == ',' || s[i] == '!' || s[i] == '?' || s[i + 1] == '\0')
- {
- if (isTargetWord)
- {
- strcat(tmp, "<i><b>");
- strcat(tmp, word);
- strcat(tmp, "</b></i>");
- }
- else if (strlen(word) > 0)
- {
- strcat(tmp, word);
- }
- word[0] = '\0';
- k = 0;
- isTargetWord = false;
- tmp[strlen(tmp)] = s[i];
- }
- else
- {
- if (s[i] == 'A')
- {
- word[k++] = '*';
- isTargetWord = true;
- }
- else
- {
- word[k++] = s[i];
- }
- word[k] = '\0';
- }
- i++;
- }
- return tmp;
- }
- void main()
- {
- FILE* text_file = fopen("C:\\text_file.txt", "rt");
- FILE* html_file = fopen("C:\\html_file.html", "wt");
- char s[N];
- fgets(s, N, text_file);
- StartHtml(html_file, s);
- while (!feof(text_file))
- {
- fgets(s, N, text_file);
- fputs(NewStr(s), html_file);
- fprintf(html_file, "%s", "<BR>");
- }
- EndHtml(html_file);
- fclose(text_file);
- fclose(html_file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement