Good day to all. I would like to ask a question that, as an inexperienced programmer, I had difficulty. The essence of the task is that the text from the file and the array of delimiters are initially entered from the keyboard. then you need to perform two conversions: the first is to find the entered sequence of delimiters in the text and, if it is found more than three times, the places of all odd lines are interchanged in a circle, the second is to delete all words exceeding the user-specified length limit in odd lines.
At the moment I was able to implement text input and delimiters, search for odd lines and a search function that works successfully with single characters, but cannot find a sequence of delimiters from the array in the text.
#include "stdafx.h" #include<stdio.h> #include<conio.h> void symcount(char, char, int, int); int main(void) { setlocale(LC_ALL, "Russian"); const int numberOfCharactersToRead = 128; char* inputText = (char*)(malloc(sizeof(char) * numberOfCharactersToRead)); FILE *fp; fopen_s(&fp, "D:\\texxxt.txt", "r"); if (fp == NULL) { printf("\nФайл не найден\n"); system("pause"); return 0; } fgets(inputText, numberOfCharactersToRead, fp); printf("Введите последовательность разделителей: "); const int numberOfDelimitersToRead = 6; char* delimiters = (char*)(malloc(sizeof(char) * numberOfDelimitersToRead)); int indexer = 0; for (indexer = 0; indexer < numberOfDelimitersToRead; indexer++) { delimiters[indexer] = getchar(); } printf("\n Выведем нечётные строки для наглядности:"); //Вывод нечетных строк с указанием номеров строк int c; int y = 1; int newline = 1; while ((c = fgetc(fp)) != EOF) { if (y % 2 == 1) { if (newline) { printf("%03d | ", y ); } printf("%c", c ); } newline = (c == '\n'); if (newline) { y++; } } printf("\n"); system("pause"); //Считаем количество разделителей (вот тут и кроется проблема) int count = 0, inx; scanf_s("%p", &inputText); scanf_s("%p", &delimiters); //ищем в тексте разделители for (inx = 0; inputText[inx] != '\0'; inx++) { if (inputText[inx] == delimiters[indexer]) count++; } if (count == 0) printf("\nDeliniters '%p'are not present", delimiters); else printf("\nOccurence of delimiters '%c' : %d", delimiters, count); system("pause"); return 0; } I would be very grateful for the proposed ideas. Sorry if my questions seemed too silly :)
".,!?", then what to do when finding the sequence"???"- assume that you have found three occurrences or one? - PinkTux