×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

simple program help, counting characters and words

simple program help, counting characters and words

simple program help, counting characters and words

(OP)
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

RE: simple program help, counting characters and words

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!

RE: simple program help, counting characters and words

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.

dkil sdsd sds

has two spaces, three words

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."

RE: simple program help, counting characters and words

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."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close