Which character is first among 4 characters in c++
- by Ashiqur Rahman
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?