Question

Write a Pelles C program that takes a char array (string) and counts the number of...

Write a Pelles C program that takes a char array (string) and counts the number of consonants and vowels using a pointer

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
    char ch = ' ';
    int vowels = 0, consonants = 0;
    printf("Enter a sentence: ");
    while (ch != '\n') {
        ch = (char) getchar();
        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
                ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
                ++vowels;
            } else {
                ++consonants;
            }
        }
    }
    printf("Number of vowels = %d\n", vowels);
    printf("Number of consonants = %d\n", consonants);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a Pelles C program that takes a char array (string) and counts the number of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a python program that does the following: takes as input from the user an English...

    Write a python program that does the following: takes as input from the user an English sentence calls the function vc_counter() that: takes a string argument counts the number of vowels and consonants in the string returns a dictionary of the counts, using the keys total_vowels and total_consonants Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions. Example: Enter an English sentence: The quick brown fox's jump landed past the lazy dog! Total #...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • I need this in Visual Studio C++ Write a function that count the number of vowels,...

    I need this in Visual Studio C++ Write a function that count the number of vowels, the number of consonants and the average number of letters in each word. The function accept a C-String (char array) or a string object as an argument and return the number of vowels, number of consonants and the average number of letters in each word. Problem: Requirements: . Use pointers as part of the solution Read a string from a text file. . Write...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • Write a function that takes an array of C-strings as a parameter and the number of...

    Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.

  • Write a C++ console application that reverses an array of characters, and counts the number of:...

    Write a C++ console application that reverses an array of characters, and counts the number of:           Lower case characters (islower)           Upper case characters (isupper)           Digits (isdigit)           Other (not one of previous) Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • Write function vowelCount() that takes a string as input and counts and prints the number of...

    Write function vowelCount() that takes a string as input and counts and prints the number of occurrences of vowels in the string. >>> vowelCount('Le Tour de France') a, e, i, o, and u appear, respectively, 1, 3, 0, 1, 1 times.

  • Our lab today revolves around Character Strings (C-Strings) which are essentially character arrays. We’ll be writing...

    Our lab today revolves around Character Strings (C-Strings) which are essentially character arrays. We’ll be writing two functions that will output the number of vowels and consonants in a user inputted string. We’ll be using functions from the cstring library, so be sure to include it! We’ll be calling those functions method_one and method_two. To start off, declare a character array (with no size) called vowels and initialize it with “aeiouyAEIOUY” in our main function. Declare a character array with...

  • Write function vowelCount2() that takes a string as input and counts and prints the number of...

    Write function vowelCount2() that takes a string as input and counts and prints the number of occurrences of vowels in the string. Vowels are a, e, i, o, and u. Implement the code in the file lab5.py. This function is very similar to the function of the problem 4.25, but the vowel information which did not appear in the string should not be printed. The printing order of the vowels is a, e, i, o, u. e.g.) >>> lab5.vowelCount2(‘augustana’) a,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT