Which character is first among 4 characters in c++

Posted by Ashiqur Rahman on Stack Overflow See other posts from Stack Overflow or by Ashiqur Rahman
Published on 2012-06-20T02:46:51Z Indexed on 2012/06/20 3:16 UTC
Read the original article Hit count: 146

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about char