Character testing help

How to check if the characters before @ are part of the alphabet.

So if you have something like this:
1
2
3
char a[20];
cout <<"Enter you email:";
cin.getline(a,20);


Let's say we enter cplusplus@plus.com

How would you make sure all the characters before @ are numbers or in the alphabet?

Would this work?
size was determines by strlen
1
2
3
4
5
6
7
8
9
10
11
12
unsigned short position;
for (int i = 0 ; i < size ; i ++)
{
    if (a[i]='@';
    position = i;
 I'm a bit confused on what to do here
{
    
}
}

 
I'm also curious about making sure that there are just plain characters before that @
Assuming the ASCII character set,
1
2
3
4
5
6
7
8
9
10
#include <ctype.h>

bool CheckEMailName(const char *addr)
{
    for (const char* p = addr; p && *p && *p != '@'; ++p)
        if (!isalnum(*p))
            return false;

    return true;
}
what if you just wanted to check for characters before @?
bump?
Topic archived. No new replies allowed.