Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple program help, counting characters and words

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I've been trying to figure out how to write a program that takes a string input from a user and counts the number of characters and words in the string. If anyone can help me please do. I have no clue where to start. Also my IM name is hnugz2 if that's easier, thanks.

hnugz2
 
function 0Ah of interrupt 21h gets a string of chars input from a user. In the second byte of the returned string, it will give you the number of characters in the string, less the enter key.

As for the number of words, a very simple solution could be counting the number of spaces in the string and adding one. Kindof like:

You could count the spaces by going through the string character by character in a loop, doing a compare to 20h (the space character), and jumping on zero to increment a register. When you exit from the loop, add one more to the register, and you'll have the number of words.

Hope this helps.....

Simplicus

**186,000 miles per second. . . not just a good idea, it's the LAW!
 
Presumably you want to display the number of words and characters counted too?

I bet you'll find that tougher than counting the number of words and characters... hehehe.

By the by you better make sure to check for multiple spaces, i.e.
Code:
dkil sdsd sds
has two spaces, three words
Code:
dkil   sdsd   sds
has six spaces, three words. Better filter that out too...

Contact me at: alan@i-manila.com.ph "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Look at the "hexadecimal to decimal coversion" post to get a small routine that converts an integer to a string so you can display the number of characters. And of course vote for that post... :) "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top