Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include "testing.h"
  6. int strToWords(const char str[81], int words[40][2])
  7. {
  8. int i;
  9. int words_count;
  10.  
  11. words_count = 0;
  12. for (i = 0; i < strlen(str); i++)
  13. {
  14. if (isalpha(str[i]) || isalnum(str[i]))
  15. {
  16.  
  17. words[words_count][0] = i;
  18.  
  19. while (isalpha(str[i]) || isalnum(str[i]))
  20. {
  21. i++;
  22. }
  23. words[words_count++][1] = i - 1;
  24. }
  25. }
  26.  
  27. return words_count; // вернули количество слов в строке
  28. }
  29.  
  30. void stringInText(const char text[20][81], int strCount, const char str[81],
  31. int *lineIndex, int *colIndex)
  32. {
  33. int count_words;
  34. int words[40][2];
  35. int words_text[2][40][2];
  36. char string_word[81][81] = { 0 };
  37. char text_word[2][81][81] = { 0 };
  38. int first_index, second_index;
  39.  
  40. count_words = strToWords(str, words);
  41.  
  42. for (int k = 0; k < count_words; k++)//выделение слов из строки
  43. {
  44. first_index = words[k][0];
  45. second_index = words[k][1];
  46. for (int i = -1, j = 0; i < second_index - first_index; i++, j++)
  47.  
  48. string_word[k][j] = str[first_index + j];
  49.  
  50. }
  51. //выделение 2 строк по словам из текста
  52. count_words = strToWords(text[*lineIndex], words_text[0]);
  53. count_words = strToWords(text[*lineIndex + 1], words_text[1]);
  54. for (int s = 0; s < 2; s++)
  55. {
  56. for (int k = 0; k < count_words; k++)
  57. {
  58.  
  59. first_index = words_text[s][k][0];
  60. second_index = words_text[s][k][1];
  61. for (int i = -1, j = 0; i < second_index - first_index; i++, j++)
  62.  
  63. text_word[s][k][j] = text[s][first_index + j];
  64.  
  65. }
  66. }
  67. }
  68.  
  69.  
  70. int main()
  71. {
  72. char str[81];
  73. int words[40][2];
  74. int lineIndex = 0, colIndex = 0;
  75. char text[20][81]; //Входной массив
  76. int i, n, Count_Words; //вспомогательные переменные
  77. input_printf("Enter Stringn"); //ввод строки
  78. gets_s(str);
  79. input_printf("Enter count of stringsn"); //ввод количества строк в тексте
  80. scanf("%d", &n);
  81.  
  82. if (n > 20) //проверка количества строк
  83. error_printf("Error! Out of size");
  84. else
  85. {
  86. gets_s(text[0]);
  87. for (i = 0; i < n; i++) //ввод строк в текст
  88. {
  89. gets_s(text[i]);
  90. }
  91. }
  92. Count_Words = strToWords(str, words); // Удалить после теста
  93. for (i = 0; i < n; i++)
  94. {
  95. stringInText(text, n, str, &lineIndex, &colIndex);
  96. if (lineIndex != -1 && colIndex != -1)
  97. printf("%d %d", lineIndex, colIndex);
  98. }
  99. printf("%d", Count_Words);
  100. WAIT_ANY_KEY;
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement