Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. // Лаб. работа №11, вариант B
  2.  
  3. #include "stdafx.h"
  4. #include <string.h>
  5. #include <Windows.h>
  6.  
  7. const int N = 255;
  8.  
  9. void StartHtml(FILE* html_file, char title[])
  10. {
  11.     fputs("<HTML><HEAD><TITLE>", html_file);
  12.     fputs(title, html_file);
  13.     fputs("</TITLE></HEAD><BODY><H1>", html_file);
  14.     fputs(title, html_file);
  15.     fputs("</H1><BR>", html_file);
  16. }
  17.  
  18. void EndHtml(FILE* html_file)
  19. {
  20.     fputs("</BODY></HTML>", html_file);
  21. }
  22.  
  23. char* NewStr(char s[])
  24. {
  25.     char tmp[2 * N] = "";
  26.     int i = 0;
  27.     char word[N] = "";
  28.     int k = 0;
  29.     bool isTargetWord = false;
  30.     while (s[i] != '\0')
  31.     {
  32.         if (s[i] == ' ' || s[i] == ',' || s[i] == '!' || s[i] == '?' || s[i + 1] == '\0')
  33.         {
  34.             if (isTargetWord)
  35.             {
  36.                 strcat(tmp, "<i><b>");
  37.                 strcat(tmp, word);
  38.                 strcat(tmp, "</b></i>");
  39.             }
  40.             else if (strlen(word) > 0)
  41.             {
  42.                 strcat(tmp, word);
  43.             }
  44.             word[0] = '\0';
  45.             k = 0;
  46.             isTargetWord = false;
  47.             tmp[strlen(tmp)] = s[i];
  48.         }
  49.         else
  50.         {
  51.             if (s[i] == 'A')
  52.             {
  53.                 word[k++] = '*';
  54.                 isTargetWord = true;
  55.             }
  56.             else
  57.             {
  58.                 word[k++] = s[i];
  59.             }
  60.             word[k] = '\0';
  61.         }
  62.         i++;
  63.     }
  64.     return tmp;
  65. }
  66.  
  67. void main()
  68. {
  69.     FILE* text_file = fopen("C:\\text_file.txt", "rt");
  70.     FILE* html_file = fopen("C:\\html_file.html", "wt");
  71.     char s[N];
  72.     fgets(s, N, text_file);
  73.     StartHtml(html_file, s);
  74.     while (!feof(text_file))
  75.     {
  76.         fgets(s, N, text_file);
  77.         fputs(NewStr(s), html_file);
  78.         fprintf(html_file, "%s", "<BR>");
  79.     }
  80.     EndHtml(html_file);
  81.     fclose(text_file);
  82.     fclose(html_file);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement