February 8, 2011 at 14:25:51
Specs: Windows 7
Alright, so first off I want to make it clear I have the rest of this program working, and it is not just to mooch off of you guys and take advantage.

I need to check the LTD's of emails to verify they are legit emails.
My code seems to work fine for every email except these two:


These two should return "0" but instead always return "1"
My code is as follows for checking an LTD:

// Checks Domains .com / .edu etc.
bool CheckLtd(char* email)
int dotSymbol;
dotSymbol = Find(email, '\0', 0);
int count;
count = 0;
for (dotSymbol; email[dotSymbol] !='.'; dotSymbol--){
if ((count >= 2) && (count <= 8)){
return true;
return false;

See More: CODE WRITTEN NEED HELP debugging

Report •

February 8, 2011 at 15:52:16
You didn't post your Find(), so I'm left guessing, but I'd assume your function is counting the '.', and you're not in the first case. For the second, I'm assuming the bug is in Find(), because I couldn't duplicate the behavior with std::strrchr().

That said, I was bored, and simplified your function:

bool CheckLtd(char *email) {
  const unsigned min = 3, //Count the '.'
                 max = 9; //Count the '.'
  char *endOfStr = std::strrchr(email, 0),
       *startOfTLD = std::strrchr(email, '.');
  return startOfTLD ? (size_t)(endOfStr - startOfTLD - min) <= (max - min) : false;

EDIT: The takeaway is that pointer arithmetic is a viable option.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question