How to count characters in a sentence eliminating spaces?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Juan Garcia

    #1

    How to count characters in a sentence eliminating spaces?

    I want to count the characters of a sentence without reading any spaces.
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

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

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      Juan,

      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.

      Cheers,
      Oralloy

      Comment

      • arunkthaomas
        New Member
        • Oct 2010
        • 3

        #4
        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')

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          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.

          Comment

          Working...