I have s problem!
I have to define the number of exclamation marks that are in even rows in the text file "T" Also I have to print lines in which these characters more than two
My programm must be right but PascalABC shows me an error in line #3- "expected type"
Help me please or write your own
program text;
var
T: Text;
fName: string;
str: string;
i: integer;
numStr: integer; {Number of current string in file}
amtSymb: integer; {count !}
begin
clrscr;
write('enter input file name: ');
readln(fName);
assign(T,fName);
reset(T); {open file for reading}
numStr := 0;
while not EoF(T) do begin {Reads a line, until we reach the end of file}
readln(T,str);
inc(numStr);
if ((numStr mod 2) = 0) then begin {If an even line}
amtSymb := 0;
for i := 1 to length(str) do begin {We examine each character in the string and read "!"}
if (str[i] = '!') then
inc(amtSymb);
end;
if (amtSymb > 2) then {Display the line if more than two "!"}
writeln(str);
end;
end;
close(T);
writeln('press any key to exit...');
readKey;
end.
Most likely, it's because of a name clash between your program name text
and the Text
file type. Try renaming your program to something else.
Also, in your body you increment numStr before checking if it is even - you probably want the check before the inc
.