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 8100113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:39:29+00:00 2026-06-05T22:39:29+00:00

In my project I take a string from user and then I need to

  • 0

In my project I take a string from user and then I need to check if vowels a, e, I, O, U are present. If so, I have to find out which one comes first in the string and which one comes next after that. For example, if a user gave input something like this:

char expr[] = "this is for something real";

I comes first, then I again, then O and so on. I checked whether the characters are in the string or not using strchr(expr,'character here'). To find which character comes first, I find the index of each character using

const char *ptr = strchr(expr, characters here);
if(ptr) {
    int index = ptr - expr;
}

After that I check which index is bigger. But this is very long process.
Is there a smarter way to do this?

  • 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-05T22:39:30+00:00Added an answer on June 5, 2026 at 10:39 pm

    If you don’t need the locations in the original string, but only the order, you can use std::remove_copy_if with a functor that detects non-vowel characters (i.e. returns true for vowels):

     std::string only_vowels;
     std::remove_copy_if( std::begin(expr), std::end(expr),
                        std::back_inserter(only_vowels),
                        []( char ch ) { char upper = toupper(ch);
                                        return upper!='A' 
                                              && upper!='E'
                                              && upper!='I'
                                              && upper!='O'
                                              && upper!='U'; } );
    

    (Using C++11 features to obtain the iterators and a lambda instead of creating a functor, but the same can be written in C++03 with a bit of extra boiler plate code. Code is untested)

    After the algorithm completes, only_vowels will contain only the vowels present in the original string and in the exact order where they appeared. Case is not modified by the algorithm.

    Alternatively you can iterate manually over the elements in the string, and test each character to see whether it is a vowel, then print it or do whatever needs to be done. If this is homework, this is probably what is expected from you.

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

Sidebar

Related Questions

In my project i need to take an expression input from user as string
I have a program below that tries to take input from the user and
I have the following function which in words should take user credentials and validate
I am making a simple project where I take id and name from user
I have a Silverlight project which takes some encrypted string thru its Service Reference:
lets take for example i have a string declared: string master = 1.2.3.4; which
In an MVC project, I have an ActionLink, which, when clicked, should take an
I am developing a plugin.In this i take project as input from textbox which
I have a problem. In my project, I take sentence line by line from
Let us consider a web.config file deployed from website.... let us take another project

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.