How do i check if an element is alphanumeric?

OK, so i'm working on a program that analyzes a paragraph and checks for the word 'the'.
So far I thought of making an if statement within a loop that checks if the word 'the' appears but it's pretty complicated and ugly.

1
2
3
4
pgraph[count] == 't' || pgraph[count] == 'T' && pgraph[count + 1] == 'h' || pgraph[count + 1] == 'H'
		&& pgraph[count + 2] == 'e' || pgraph[count + 2] == 'E' &&
		pgraph[count + 3] == ' ' || pgraph[count + 3] == '!' || pgraph[count + 3] == ':' || pgraph[count + 3] == '?' pgraph[count + 3] == '.' &&
		pgraph[count - 1] == ' ' ||pgraph[count - 1] == '!' || pgraph[count - 1] == '.' || pgraph[count - 1] == '?' || pgraph[count - 1] == ':'

I was wondering if there's a way which I could just check if a the element before is a letter or not so that I know not to count that as the.

As always, thanks for the help in advanced.
To check if a character is alphanumeric, you can use isalnum, and for just alphabetic, there's isalpha, both of which are found in <cctype>:
http://www.cplusplus.com/reference/cctype/

But can't you just use string::find to search for the word "the"?
http://www.cplusplus.com/reference/string/string/find/
Last edited on
yeah, I was thinking about doing that but my professor specified not to use strings, and rather treat the paragraph as a series of strings.
Hmm...well, you could use tolower to avoid having to check for uppercase and lowercase. (So something like if (tolower(pgraph[count]) == 't' && /* ... */))
Also keep in mind that && has a stronger precedence than ||, so if (A || B && C) is equivalent to if (A || (B && C)), not if ((A || B) && C).

I'd imagine that the word "the" wouldn't be at the end of any sentence, and there should be a space between the end of a sentence and the first word of the next sentence, so you could probably just check for a space before and after each occurrence of "the".
You should also check the first word of the paragraph, since there probably won't be a space before it, and that word could easily be "the".
Topic archived. No new replies allowed.