Подсчитать количество символов слов и предложений в текстовом файле на языке pascal
Категория: Delphi/Pascal
2011-08-28 22:44:47
code: #pascal
- procedure Counter(var symbols,words,sentences:integer);
- var f:text;
- letter:char;
- end_of_word, end_of_sentence:boolean;
- begin
- symbols:=0;
- words:=0;
- sentences:=0;
- end_of_word:=false;
- end_of_sentence:=false;
- assign(f,'file.txt');
- reset(f);
- while not eof(f) do
- begin
- Read(f,letter);
- symbols:=symbols+1;
- if letter in [' ' , '.' , ',' , ';' , ':' , '-', #10, #13, #9] then
- begin
- if not end_of_word then
- words:=words+1;
- end_of_word:=true;
- if not end_of_sentence and (letter='.') then
- begin
- end_of_sentence:=true;
- sentences:=sentences+1
- end;
- end
- else
- begin
- end_of_word:=false;
- end_of_sentence=false
- end;
- end;
- if not end_of_word then
- words:=words+1;
- if not end_of_sentence then
- sentence:=sentences+1;
- close(f);
- end;
Поделиться: