Home > Back-end >  C language help post (email address in the judgment of the @ symbol)
C language help post (email address in the judgment of the @ symbol)

Time:05-14

Judgment with c language email address the following four points, appear a quote error
1. The email address of the first is the @ symbol
2. The email address in the last one is the @ symbol
3. Email address does not appear in the @ symbol
4. In the email address above 2 times the @ symbol

CodePudding user response:

 # include & lt; stdio.h> 
#include

Int check_at_ch SRC (char *);

Int main ()
{
Char STR []="xx @ XXXX";

If (check_at_ch (STR) & lt; 0)
Printf (" error! \n");

Printf (" % d \ n ", check_at_ch (STR));

return 0;
}

Int check_at_ch (char * SRC)
{
Char * PSTR;
Unsigned int pos.

PSTR=STRCHR (SRC, '@');
if (! PSTR)//no '@'
The return - 3;

Pos=PSTR - SRC;
If (pos==0)//at first
return -1;
Else if (pos==strlen (SRC) - 1)//at the end
The return - 2;
Else if (STRCHR (PSTR + 1, '@'))//appear more than 2 times
The return - 4;
The else
return 0;
}

For your reference ~
  • Related