How to determine a special character in a string?

I have to make an email validation program and i am halfway done. I only have one more problem, consider the ff. example:

Enter email:
myemail.@something.com //this is the input
Invalid //this should be the output

How can i determine if there is a special character near the '@' sign? and vice versa?
Last edited on
By special character do you mean any character that is not part of the alphabet A-z?

If so, http://www.cplusplus.com/reference/cctype/isalpha/

Just use a loop going through the string, check everything before "@" if there is anything in there that returns false to isalpha() then print invalid.
Yep, does it also include numbers 0-9?
Last edited on
isalpha does not include 0-9.

You would want http://www.cplusplus.com/reference/cctype/isalnum/ for that
Thanks, i got it.

but i can't seem to get this to work:

1
2
3
4
5
6
7
8
for (i = 0; i < strlen(str); i++)
      {
          if(isalpha(str[i]) == '@')
          {
                 cout<<"Validddd";           
          }
          
      }


Am i doing something wrong? i don't know what comes after that
Last edited on
Topic archived. No new replies allowed.