By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

How to count characters in a sentence eliminating spaces?

P: n/a
I want to count the characters of a sentence without reading any spaces.
Sep 27 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 2,400
"... without reading any spaces."
Do you mean 'without counting any of the spaces'?

What is the format of the sentence. Typically such things are formatted as null-terminated strings, but there are other possibilities. It is up to you to find out.

When you say 'spaces', do you mean 'any whitespace'? For example, do you want to count tab characters, newlines, etc? It is up to you to find out what characters shouldn't be counted.

The count you want is the total size of the sentence minus the number of not-to-be-counted characters in the sentence. Treat each of these as a separate problem.
Sep 27 '10 #2

Expert 100+
P: 983

This sounds like a homework question.

Why don't you try telling us what your requirements are and a preliminary solution. Once that's done, we can give you better help.

Sep 27 '10 #3

P: 3
using a for loop, count the no of words and subtract the number of words from the value of i(when it reach the '\0')
Oct 1 '10 #4

Expert 100+
P: 2,400
Your first post says to count characters, your most recent post says to count words. Which is it?

How would you describe how to recognize the beginning and end of a word? (using words, not a computer program)

Your most recent post refers to "the value of i". You haven't told us anything about what variable i is.
Oct 1 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.