•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 375,276 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,065 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
A function that takes a string and returns the number of words in the string. An example of using pointers in Pascal.
// count words in a string using pointers // Pascal code used in a Delphi 3.0 program function WordsCount(s: string ): integer; var ps: PChar; nSpaces, n: integer; begin n := 0; // make it a string that ends with value zero s := s + #0; // point to start of string s ps := @s[ 1 ]; // keep loop going up to zero ending while( #0 <> ps^ ) do begin // checks for space = ' ' while((' ' = ps^) and (#0 <> ps^)) do begin inc( ps ); end; nSpaces := 0; while((' ' <> ps^) and (#0 <> ps^)) do begin inc(nSpaces); inc(ps); end; if (nSpaces > 0) then begin inc( n ); end; end; Result := n; end;
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)