Identifying the next character in a string is capital or not

2.5k views Asked by At

I am writing a C++ program. I have an array of char array trans[20][100]. Actually each string of trans is a transition of a grammar(Programming language translators). I want to check for each string in trans whether there is a Non-terminal after a '.' i.e. i want to check if in the strings there is a '.' followed by any capital letter. Can anyone please tell me how to do it??
-Thanks in advance

3

There are 3 answers

1
Renaud On BEST ANSWER

If you operate on ASCII char, then you could test if the int value of the char is between 65 and 90. See the ASCII table.

1
artyom.stv On

You can use any RegExp library (e.g. this one). The test regular expression is /\.[A-Z]/.

Or for ASCII string you can use:

int strHasDotCap(const char *s)
{
    while (*s) {
        if (*s++ == '.') {
            if (*s >= 'A' && *s <= 'Z') return 1;
        }
    }
    return 0;
}
0
Outspoken On

You can use the functions in ctype.h isAlpha(), isUpper() etc. if the characters are ASCII type.