how to check if the second last character of a word is vowel in c++ character array?

how to check if the second last character of a word is vowel in c++ character array?
1
2
3
4
5
6
bool is_vowel( char c )
{
    c = std::tolower( c );
    return c == 'a' || c == 'e' || c == 'i' || 
           c == 'o' || c == 'u';
}
without string?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstring>
#include <iostream>
#include <string>

bool is_vowel(char c);

int main()
{
    std::cout << "\nPlease, give me a string! --> ";
    std::string str;
    std::getline(std::cin, str);

    char* cstr = new char[str.length()+1];
    strcpy(cstr, str.c_str());

    // Assuming we don't know the dimension, check wether the last but one
    // character in cstr is a vowel or not:
    int index {0};
    for(; cstr[index]!='\0'; index++) {} // \0 == null-terminating character 
    char c = cstr[index-2];
    if(is_vowel(c)) {
        std::cout << "Hallelujah! \'" << c << "\' is a vowel.\n\n";
    } else {
        std::cout << "It's my painful duty to inform you that \'" 
                  << c << "\' is not a vowel.\n\n";
    }

    delete cstr;

    return 0;
}

// copyright: integralfx
bool is_vowel( char c )
{
    c = std::tolower( c );
    return c == 'a' || c == 'e' || c == 'i' || 
           c == 'o' || c == 'u';
}



Please, give me a string! --> Here you are a string! Are you happy now?
It's my painful duty to inform you that 'w' is not a vowel.

Please, give me a string! --> Here you are a string! There are vowels, too!
Hallelujah! 'o' is a vowel.


It's my painful duty to inform you that 'w' is not a vowel.

Ah, @Enoizat, in certain parts of the world ...
http://www.101languages.net/welsh/vowels.html

I mean, how else are you going to say
http://www.llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk/
Happy to learn a new thing, lastchance! :-)
Thank you a lot.
I'm still struggling with my poor English, but one day maybe I'll try to study Welsh, too!
Topic archived. No new replies allowed.