Thread: Counting vowels

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    9

    Counting vowels

    Hi. I'm quite new to C and I'm supposed to make a program that asks a user for a paragraph, and the program will print the number of vowels in it. I'm only allowed to use printf and scanf functions. Arrays and pointers are not allowed.
    And I'm at lost as how to do this. Help?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,727
    Since you only want the number of vowels, you certainly do not need an array: you can read the input character by character, checking if the current character is a vowel.

    However, you will need to use a pointer since to read a character with scanf, you will have to pass a pointer to the char variable as an argument.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    9
    is there no way to do this without using a pointer?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,727
    There is, if you use say, getchar instead of scanf, but you are supposed to use scanf.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2016
    Posts
    9
    I see. How do you break a loop on the condition that the user hits the enter key?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,727
    Check to see if the current character is the newline character, i.e., '\n'.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting Vowels and Characters:
    By jocdrew21 in forum C Programming
    Replies: 4
    Last Post: 07-30-2013, 11:16 AM
  2. Counting vowels
    By rmrjr22 in forum C Programming
    Replies: 23
    Last Post: 11-14-2012, 04:26 PM
  3. Counting vowels
    By skg29 in forum C Programming
    Replies: 3
    Last Post: 04-29-2012, 01:48 AM
  4. Need help with counting vowels prog
    By truetrini20 in forum C++ Programming
    Replies: 9
    Last Post: 07-12-2010, 07:44 AM
  5. counting vowels
    By trippedwire in forum C++ Programming
    Replies: 10
    Last Post: 10-01-2004, 11:58 PM