Help make the last task in Pascal, or at least tell me how it can be done. Condition:

In the text file input.txt recorded Russian multi-line text. Find in the text words containing at least three letters from the first word of the text, write them in capital letters and indicate the letters found after each such word in brackets. The resulting text is written to the file output.txt. All text, except for the words found, must remain unchanged, including punctuation marks.

I was told that approximately it is done this way: the input file is read character by character, if the character is in the alphabet (Russian letters + punctuation), then this character is immediately written to the output file. At the same time, along the way, it is necessary to select words to check for compliance with the condition, and in the brackets after the desired word, write the matched letters). The main problem is that when reading character by character I do not even know how to select the letters from the first word. Therefore, I read every line of text, parse it into words that I add to the array, etc. The program seems to give some kind of result, but I very much doubt its correctness. Here is my program: http://ideone.com/eIQIqO Help make it the way I was recommended. I think this is the most universal way, such a program will process any text with lines of any length.

    1 answer 1

    Where is the problem? Basically, you do everything right.

    The only suspicious place is in GetWords: are you sure a[n]:=a[n]+s[i]; in the end need? In my opinion, no. And if _word <> ' ' check seems to be redundant.

    The reading-by-character approach seems to me unnecessarily complicated, although it also has the right to life.

    • > a [n]: = a [n] + s [i]; Added because without this line the last punctuation mark was not copied to output. I don’t know how to do it without it, but with this line the code looks less beautiful and annoying. And in my decision, I very much doubt - it is enough to drop the task text into the input file, adding the word "output" before all the text, for example (the word B is too short), as a strange result is obtained. For example, repeated letters in brackets - although I do not know whether it is permissible or not. And if one line is more than 255 characters, the program will crash. - typemoon pm
    • @typemoon: do not pay attention to 255 characters, for an educational task it will come down, this is a language restriction. - VladD
    • @typemoon: repeating letters in brackets seems to be no problem either. Although it depends on how you interpret the task, of course. What is the problem with "B"? It should not be 3 letters, and what happens at the output? (I do not have the Pascal compiler at hand, but for ideone your code was too tough.) - VladD
    • And what should the algorithm be about when reading character by character? I didn’t get further than this: ideone.com/TS9tN8 Moreover, for some reason, the output string of non-alphabetical characters is never executed here. It should be like this: if the symbol is in the alphabet, the word assembly algorithm is launched, otherwise (if the symbol is not in the alphabet), it is simply written to the file. It seems to me that this is because read (input, c) is executed once again. - typemoon
    • With the letter B, it seems, it works:> Russian multi-line text is written in the TEXT (in) file. Find in the text words containing at least three letters from the first word of the text, write them in capital letters and indicate the letters found after each such word in ULKSKAKHV (BBB). The resulting text is written to the file output. All text, except for the words found, should remain LEGENDABLE (BBB) ​​including punctuation marks. But I am afraid that it is necessary to have at least three different letters, and for this purpose to organize a cycle by words. - typemoon