Given the text. Type all words other than the last one
having previously converted each of them according to the following rule: - swap the first and last letters of the word;

  • Sorry, I forgot the task on the ASCIIZ - lines (lines with zero ending), I did not understand how they differ. Do you need another solution or what? explain. - lybntras
  • If your question is to work with PChar type strings, then PChar is not exactly a string - it is a pointer to the beginning of a line. The length of such a string is not stored anywhere (the length of a normal string is stored in a symbol with a zero index): there is a pointer to the beginning of such a string, and its end is a null symbol. And which version of Pascal do you use? - DelphiM0ZG
  • free pascal 2.4.4 - lybntras
  • This is material on this topic, but I did not understand what was happening - lybntras

1 answer 1

Here, what happened with me:

Program words; Uses CRT; Var StrMas: Array[0..199] Of String; Str, MStr: String; MasInd, StrInd, StrLen, i: Word; C: Char; Begin Write('Введи строку: '); ReadLn(Str); StrLen:=Length(Str); StrInd:=1; MasInd:=0; While (StrInd<=StrLen) Do Begin While ((Str[StrInd]=' ') And (StrInd<=StrLen)) Do Inc(StrInd); MStr:=''; While ((Str[StrInd]<>' ') And (StrInd<=StrLen)) Do Begin MStr:=MStr+Str[StrInd]; Inc(StrInd); End; If (MStr<>'') Then Begin C:=MStr[1]; MStr[1]:=MStr[Length(MStr)]; MStr[Length(MStr)]:=C; StrMas[MasInd]:=MStr; End Else Break; Inc(MasInd); Inc(StrInd); End; For i:=0 To MasInd-2 Do If (StrMas[i]<>StrMas[MasInd-1]) Then WriteLn(StrMas[i]); WriteLn('Нажми на кнопку ANY KEY!!!'); Repeat Until (KeyPressed); End. 

First I enter a string, break it into words, discarding all (including extra) spaces with a loop, then in a loop I type a string (word), then swap the first and last character of the word and assign an element to the array (if, of course, there is something to assign ), and then print the required words.