Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:03:40+00:00 2026-06-18T16:03:40+00:00

I have been stuck on this program all day. I finally feel like I’m

  • 0

I have been stuck on this program all day. I finally feel like I’m getting really close. I have to find the number of vowels and characters in a string. Then output them at the end. However, when I compile my program crashes. I have checked syntax and looked in my book all day. If anyone can help I would really appreciate it! because I have 5 more similar functions to write that manipulate c-strings. Thanks!

#include <iostream>
#include <string>
using namespace std;

int specialCounter(char *, int &);


int main()
{

const int SIZE = 51;        //Array size
char userString[SIZE];      // To hold the string
char letter;
int numCons;



// Get the user's input string
cout << "First, Please enter a string (up to 50 characters): " << endl;
cin.getline(userString, SIZE);





// Display output
cout << "The number of vowels found is " << specialCounter(userString, numCons) <<      "." << endl;
cout << "The number of consonants found is " << numCons << "." << endl;


}



int specialCounter(char *strPtr, int &cons)
{
int vowels = 0;
cons = 0;


while (*strPtr != '/0')
{
    if (*strPtr == 'a' || 'A' || 'e' || 'E' || 'i' || 'I' || 'o' || 'O' || 'u' || 'U')
    {
        vowels++;       // if vowel is found, increment vowel counter
                    // go to the next character in the string
    }
    else
    {
        cons++;         // if consonant is found, increment consonant counter
                    // go to the next character in the string
    }

    strPtr++;

}
return vowels;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:03:41+00:00Added an answer on June 18, 2026 at 4:03 pm

    I’m going to assume you’re limited to not using std::string or std::getline and that you have to assume the user inputs something less than 51 characters.

    Your crash stems from:

    while (*strPtr != '/0')
    

    A null character is an escape code. '/0' is a multicharacter literal with an implementation-defined value. That means it’s probably always true. Change it to:

    while (*strPtr != '\0') //or while (strPtr)
    

    Apart from that, you have a logic error with your vowel check. You have to check it against each vowel, like this:

    if (*strPtr == 'a' || *strPtr == 'e') //etc.
    

    You’ll find it easier if you compare against the toupper or tolower version of each character to reduce the number of comparisons by a factor of 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been stuck on this and don't really know how to go about
I have been staring at this all day and I am having a difficult
I have been stuck on this for a while now and I cannot seem
I have been stuck on this for days, and was wondering if anyone had
I have been stuck on this for a while. i have tried and I
I have been stuck on this silly if statement, whatever i do, I cannot
so i have been stuck with this issue for 3 weeks now and i
I have now been stuck at this for some time so I though to
I have been stuck for a long time on this simple but obtuse message
i know this is basic but somehow i have been stuck here for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.