Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //#include "stdafx.h"
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <clocale>
- #include <ctype.h>
- #include <conio.h>
- #define MAX_SENTENCES 500
- #define MAX_WORDS 50
- #define _CRT_SECURE_NO_WARNINGS
- #pragma warning (disable : 4996)
- using namespace std;
- class string_parser {
- public:
- int get_sentences(char *p, int *sentence, int *coord);
- };
- int main()
- {
- setlocale(LC_ALL, "rus");
- string_parser sp;
- char str[1024];
- char fname[128];
- FILE *fp;
- printf("Имя файла: ");
- scanf("%s", &fname[0]);
- fp = fopen(fname, "r");
- if (fp == NULL) {
- printf("Ошибка открытия файла\n");
- return -1;
- }
- char *p = &str[0];
- memset(&str[0], '\0', sizeof(str));
- while (!feof(fp)) {
- *p = fgetc(fp);
- p++;
- }
- *(p - 1) = ' ';
- int coord[MAX_SENTENCES][2];
- int sentence = 0;
- memset(coord, -1, sizeof(coord));
- sp.get_sentences(&str[0], &sentence, &coord[0][0]);
- printf("Предложений: %d\n", sentence);
- p = &str[0];
- int pos = 0;
- int curs = 0;
- int s[3] = { 1, 0, 2 };
- for (int i = 0;i <= sentence;i += 3) {
- for (int j = 0;j<3;j++) {
- if (i + s[j] >= sentence)
- break;
- getch();
- system("cls");
- while (*p != '\0') {
- if (coord[i + s[j]][0] == pos)
- putchar('[');
- if (coord[i + s[j]][1] == pos - 1)
- putchar(']');
- putchar(*p);
- pos++;
- p++;
- }
- p = &str[0];
- pos = 0;
- curs++;
- }
- }
- printf("\n");
- system("pause");
- return 0;
- }
- int string_parser::get_sentences(char *p, int *sentence, int *coord)
- {
- int pos, ld, inside;
- pos = ld = inside = 0;
- *sentence = 0;
- while (*p != '\0') {
- if ((isalpha(*p) || isdigit(*p)) && !inside) {
- *(coord + *sentence * 2 + 0) = pos;
- inside = 1;
- pos++;
- p++;
- continue;
- }
- if (*p == '.' || *p == '!' || *p == '?') {
- if (pos - ld == 1) {
- ld = pos;
- pos++;
- p++;
- continue;
- }
- ld = pos;
- *(coord + *sentence * 2 + 1) = pos;
- (*sentence)++;
- inside = 0;
- }
- p++;
- pos++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement