Hi masters,,
how can i count how many words in sentences using pascal?

thanks before and best regards.

Recommended Answers

All 2 Replies

see if this help:

Program CountingWords;
Uses WinCrt;
Var JumPhrase : Integer;
Phrase : String;
Ul : Char;
Procedure CheckWords(Teks: String; Var CW: Integer);
Var i: Integer;
Begin
	If (Teks[1]=' ') Then
		CW:=0
	Else
		CW:=1;
	For i:= 1 To Length(Teks) Do
	Begin
		If (Teks[i]=' ') And (Teks[i+1]<>' ') And (Teks[i+2]<>' ') Then
		Inc(CW)
		Else If (Teks[i]='-') And (Teks[i-1]<>' ') And (Teks[i+1]<>' ')
		Then
		Inc(CW);
	End;
End;
Begin
	Repeat
	Clrscr;
	Writeln('Counting Words');
	Writeln('============================================');
	Writeln;
	Writeln('Input Sentences:');Readln(Phrase);
	CheckWords(Phrase,JumPhrase);
	Writeln;
	Writeln('Number of words in the sentence is : ',JumPhrase,' Pieces');
	Writeln;
	Write('Try Again [Y/N]: ');Ul:=Upcase(Readkey);
	Until Ul<>'Y';
End.
commented: working like a charm. +4

Its Working sir.
thank you so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.