Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include "testing.h"
- int strToWords(const char str[81], int words[40][2])
- {
- int i;
- int words_count;
- words_count = 0;
- for (i = 0; i < strlen(str); i++)
- {
- if (isalpha(str[i]) || isalnum(str[i]))
- {
- words[words_count][0] = i;
- while (isalpha(str[i]) || isalnum(str[i]))
- {
- i++;
- }
- words[words_count++][1] = i - 1;
- }
- }
- return words_count; // вернули количество слов в строке
- }
- void stringInText(const char text[20][81], int strCount, const char str[81],
- int *lineIndex, int *colIndex)
- {
- int count_words;
- int words[40][2];
- int words_text[2][40][2];
- char string_word[81][81] = { 0 };
- char text_word[2][81][81] = { 0 };
- int first_index, second_index;
- count_words = strToWords(str, words);
- for (int k = 0; k < count_words; k++)//выделение слов из строки
- {
- first_index = words[k][0];
- second_index = words[k][1];
- for (int i = -1, j = 0; i < second_index - first_index; i++, j++)
- string_word[k][j] = str[first_index + j];
- }
- //выделение 2 строк по словам из текста
- count_words = strToWords(text[*lineIndex], words_text[0]);
- count_words = strToWords(text[*lineIndex + 1], words_text[1]);
- for (int s = 0; s < 2; s++)
- {
- for (int k = 0; k < count_words; k++)
- {
- first_index = words_text[s][k][0];
- second_index = words_text[s][k][1];
- for (int i = -1, j = 0; i < second_index - first_index; i++, j++)
- text_word[s][k][j] = text[s][first_index + j];
- }
- }
- }
- int main()
- {
- char str[81];
- int words[40][2];
- int lineIndex = 0, colIndex = 0;
- char text[20][81]; //Входной массив
- int i, n, Count_Words; //вспомогательные переменные
- input_printf("Enter Stringn"); //ввод строки
- gets_s(str);
- input_printf("Enter count of stringsn"); //ввод количества строк в тексте
- scanf("%d", &n);
- if (n > 20) //проверка количества строк
- error_printf("Error! Out of size");
- else
- {
- gets_s(text[0]);
- for (i = 0; i < n; i++) //ввод строк в текст
- {
- gets_s(text[i]);
- }
- }
- Count_Words = strToWords(str, words); // Удалить после теста
- for (i = 0; i < n; i++)
- {
- stringInText(text, n, str, &lineIndex, &colIndex);
- if (lineIndex != -1 && colIndex != -1)
- printf("%d %d", lineIndex, colIndex);
- }
- printf("%d", Count_Words);
- WAIT_ANY_KEY;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement