Plz help with word counting code

iam having trouble trying to develop a code which will allow me to read a text file and then count how many words are in it.. Please if possible can someone help me abit?? that would be greatly appreciated

Comments

  • : iam having trouble trying to develop a code which will allow me to read a text file and then count how many words are in it.. Please if possible can someone help me abit?? that would be greatly appreciated
    :
    Here's an idea. Make 3 vars: I'll call them ThisChar:byte, LastChar:byte, and WordCount:longint. Open the file as a file of bytes. Initialise ThisChar to 32 or below, and WordCount to 0. Make a loop which iterates while not eof.

    Inside the loop to this: Assign ThisChar to LastChar. Read from the file to ThisChar. If (ThisChar>32)and(LastChar<33) then inc(WordCount). You may need to check the ASCII table to refine this condition, but it is fairly accurate. The last character read from the file is in ThisChar, so you can use this to print to the screen or whatever else you need. End the loop, close the file, and do whatever else needs doing.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion