Thread: counting characters and vowels and constants including after spaces.

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    2

    Angry counting characters and vowels and constants including after spaces.

    i am trying to write a program that counts characters, vowels and constants in a string.
    it works fine when entering one word i.e hello but when i add a space i.e hello Jon it doesn't count after the space
    any ideas would be great help, prob something simple.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I'm sure it is. I will take a guess, and say you need to read the documentation for scanf carefully to identify and possibly correct your problem. If you don't find your answer there, post your code.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    2
    Quote Originally Posted by anduril462 View Post
    I'm sure it is. I will take a guess, and say you need to read the documentation for scanf carefully to identify and possibly correct your problem. If you don't find your answer there, post your code.
    do you no the code to include spaces (white spaces) maybe i need to put that in my scanf

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    another option is to avoid scanf. use fgetc to read one character at a time so you can test each one individually.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    You could use the "%[...]" format specifier, replacing the ... with the characters you want to allow (or ^ followed by the characters you don't want to allow, such as \n). Personally though, I would use fgets, since it makes it easy to protect against buffer overflows too. Read this FAQ article for more info: FAQ > Get a line of text from the user/keyboard (C) - Cprogramming.com.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting vowels in a string - invalid identifier
    By hencherz in forum C++ Programming
    Replies: 11
    Last Post: 02-25-2012, 05:38 AM
  2. Replies: 1
    Last Post: 11-08-2011, 01:13 PM
  3. Need help with counting vowels prog
    By truetrini20 in forum C++ Programming
    Replies: 9
    Last Post: 07-12-2010, 07:44 AM
  4. Counting Vowels within a string.
    By patso in forum C Programming
    Replies: 12
    Last Post: 04-09-2008, 04:21 PM
  5. counting vowels
    By trippedwire in forum C++ Programming
    Replies: 10
    Last Post: 10-01-2004, 11:58 PM