Thread: cant understand this , count vowels

  1. #1
    Registered User
    Join Date
    Oct 2011

    Wink cant understand this , count vowels

    Hello guys

    Our Dr in college asked me to do this exercise and I'm guessing he doesn't want Arrays in it , because we didn't study Arrays yet.

    And I asked him if he wants me to put single characters only and count vowels or write a whole line , and he said we have to type a line not single characters

    this is the question :

    Write a program to count the vowels and letters in free text given as standard input. Read text a character at a time until you encounter end-of-data.

    Then print out the number of occurrences of each of the vowels a, e, i, o and u in the text, the total number of letters, and each of the vowels as an integer percentage of the letter total.

    Suggested output format is:

    Numbers of characters:
    a 3 ; e 2 ; i 0 ; o 1 ; u 0 ; rest 17
    Percentages of total:
    a 13%; e 8%; i 0%; o 4%; u 0%; rest 73%

    Read characters to end of data using a construct such as

    char ch;
    ( ch = getchar() ) >= 0
    ) {
    /* ch is the next character */ ....

    to read characters one at a time using getchar() until a negative value is returned.

    Last edited by y0us3f; 10-24-2011 at 03:09 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    So you'll want to get input from the user, with fgets(). After that, it's just a loop in which you will count out the vowels, and keep your variables updated.

    You'll want to use the code tags for showing code properly, on the forum. (Advanced editor, using the # icon, paste your code between the tags it puts in the editor for you.)

  3. #3
    Registered User svanski's Avatar
    Join Date
    Oct 2011
    adding on to what Adak said I would use switch statement. Let your cases be a, e, i, o, u and rest. every time you encounter have some counter that will be incremented. at the end just calculate %es and you are good.

    The C switch Statement (C)

    this is switch statement in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Count the number of vowels, consonants, digits etc.
    By kumar14878 in forum C Programming
    Replies: 3
    Last Post: 05-09-2005, 12:34 AM
  2. Replies: 1
    Last Post: 03-06-2005, 10:12 AM
  3. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM
  4. Replies: 2
    Last Post: 05-05-2002, 01:38 PM
  5. Trying to count vowels in a string assignment
    By NCCMelissa in forum C Programming
    Replies: 8
    Last Post: 04-16-2002, 12:25 AM